Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Ref in OpenApiVersion #2377

Closed
nikitasius opened this issue Apr 13, 2022 · 11 comments
Closed

Support Ref in OpenApiVersion #2377

nikitasius opened this issue Apr 13, 2022 · 11 comments
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... type/feature

Comments

@nikitasius
Copy link

nikitasius commented Apr 13, 2022

Description:

I add a param OpenApiVersionParam with a value 3.0.3 and it doesn't pass the validation sam validate

Steps to reproduce:

Parameters:
  StageNameParam:
    Type: String
    Default: "debug"
    Description: API Stage name
  OpenApiVersionParam:
    Type: String
    Default: "3.0.0"
    Description: to remove fcking default Stage

and below in Resources:

FAILS:

  DebugApi:
    Type: AWS::Serverless::Api
    Properties:
      OpenApiVersion: !Ref OpenApiVersionParam
      StageName: !Ref StageNameParam
      EndpointConfiguration:
        Type: REGIONAL

WORK:

  DebugApi:
    Type: AWS::Serverless::Api
    Properties:
      OpenApiVersion: 3.0.3
      StageName: !Ref StageNameParam
      EndpointConfiguration:
        Type: REGIONAL

Observed result:

Fails: Error: [InvalidResourceException('DebugApi', "The OpenApiVersion value must be of the format '3.0.0'.")] ('DebugApi', "The OpenApiVersion value must be of the format '3.0.0'.")

Expected result:

Should work.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Linux pentagon 5.10.0-13-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64 GNU/Linux
  2. If using SAM CLI, sam --version: SAM CLI, version 1.46.0
  3. AWS region: eu-west-1
@jfuss
Copy link
Contributor

jfuss commented Apr 13, 2022

@nikitasius Does this only happen locally?

@nikitasius
Copy link
Author

@nikitasius Does this only happen locally?

hi, just tested, nope:

Waiting for changeset to be created..
Error: Failed to create changeset for the stack: TL-DEBUG, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [DebugApi] is invalid. The OpenApiVersion value must be of the format '3.0.0'.

@nikitasius
Copy link
Author

i.e. 3.0.0, 3.0.3 - same error when i pass is as a variable.

@mndeveci
Copy link
Contributor

Looking at the code, SAM only validates against constant values therefore intrinsics are not supported for this field. See;

https://github.com/aws/serverless-application-model/blob/develop/samtranslator/model/api/api_generator.py#L265

def get_openapi_versions_supported_regex():

What is your use case here, where you need dynamic value of Open API version?

Thanks!

@mndeveci mndeveci added the area/intrinsics Ref, If, Sub, GetAtt, ... label Apr 14, 2022
@nikitasius
Copy link
Author

What is your use case here, where you need dynamic value of Open API version?

i just want to generate configs using Parameters. I define the solid base in the parameters and just use a template with !Ref to apply the values, instead of manually changing the numbers.

btw, 3.0.3 or 3.0.0 passing fine the regex
image

AWS CloudFormation compatibility: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent.
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-api.html#sam-api-openapiversion

Well, guess in this case it's a bug in SAM tool. Becase you allow to use "sam's unique only" features but you don't properly filter the configs.

@jfuss
Copy link
Contributor

jfuss commented Apr 14, 2022

@nikitasius This comes down to how/where intrinsics are resolved. CloudFormation does not resolve intrinsics before calling SAM (or any CloudFormation Macro), so SAM has to re-implement behavior. We don't have a consistency here and tend to try not to resolve things, so we don't have to handle re-implementing resolving.

So yes, your string passes the regex but SAM actually gets the Ref: OpenApiVersionParam instead of the value 3.0.3.

Is there any reason you want to define this in a parameter? Usually they are for things that change often, which I assume this does not? Maybe I am missing some other use case that make this value. I only ask because of the above comment on where intrinsics get resolved, it would be nice if CloudFormation would just do a pass before calling SAM but that is a complete aside here.

@nikitasius
Copy link
Author

Is there any reason you want to define this in a parameter? Usually they are for things that change often, which I assume this does not?

@j0lly to be honest i don't want to create philosophic discussions to be or not to be, etc. As i told before, i build a parameter set and use it.
SAM and/or Cloudformation do the things wrong. Thats all, this !Ref doesn't work.

@jfuss
Copy link
Contributor

jfuss commented Apr 14, 2022

@nikitasius It helps us understand the use-case and the why. I understand the view point of just make this work but there are reasons (as described above) it doesn't work today.

With that, this is a feature request to add Ref support and the way you will need to do this today is by providing inline and not using intrinsic functions.

@jfuss jfuss changed the title OpenApiVersion: !Ref OpenApiVersionParam fails Support Ref in OpenApiVersion Apr 14, 2022
@nikitasius
Copy link
Author

With that, this is a feature request to add Ref support and the way you will need to do this today is by providing inline and not using intrinsic functions.

thanks. Yep i provide it as is w/o !Ref have no choice :)

@hoffa
Copy link
Contributor

hoffa commented Oct 12, 2022

Can you try adding AWS::LanguageExtensions to you Transforms? (see #2533)

This works:

Transform:
  - AWS::LanguageExtensions
  - AWS::Serverless-2016-10-31
Parameters:
  MyParameter:
    Type: String
    Default: 3.0.0
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      OpenApiVersion: !Ref MyParameter
      StageName: prod
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: nodejs16.x
      Handler: index.handler
      InlineCode: console.log("hi!")
      Events:
        ApiEvent:
          Type: Api
          Properties:
            Method: GET
            Path: /
            RestApiId: !Ref MyApi

@hoffa hoffa added blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days area/intrinsics-static and removed blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days labels Oct 17, 2022
@hoffa
Copy link
Contributor

hoffa commented Nov 3, 2022

Closing in favor of #2533.

@hoffa hoffa closed this as completed Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... type/feature
Projects
None yet
Development

No branches or pull requests

6 participants