Skip to content

Support Ref in OpenApiVersion #2377

Closed
Closed

Description

@nikitasius

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

Activity

  1. jfuss commented on Apr 13, 2022

    @jfuss
    Contributor

    @nikitasius Does this only happen locally?

  2. nikitasius commented on Apr 13, 2022

    @nikitasius
    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'.
    
  3. nikitasius commented on Apr 13, 2022

    @nikitasius
    Author

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

  4. mndeveci commented on Apr 14, 2022

    @mndeveci
    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!

  5. added
    area/intrinsics
    on Apr 14, 2022
  6. nikitasius commented on Apr 14, 2022

    @nikitasius
    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.

  7. jfuss commented on Apr 14, 2022

    @jfuss
    Contributor

    @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.

  8. nikitasius commented on Apr 14, 2022

    @nikitasius
    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.

  9. jfuss commented on Apr 14, 2022

    @jfuss
    Contributor

    @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.

  10. changed the title [-]OpenApiVersion: !Ref OpenApiVersionParam fails[/-] [+]Support Ref in OpenApiVersion[/+] on Apr 14, 2022
  11. nikitasius commented on Apr 15, 2022

    @nikitasius
    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 :)

  12. hoffa commented on Oct 12, 2022

    @hoffa
    Contributor

    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
  13. added
    blocked/close-if-inactive
    and removed
    blocked/close-if-inactive
    on Oct 17, 2022
  14. hoffa commented on Nov 3, 2022

    @hoffa
    Contributor

    Closing in favor of #2533.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/intrinsicstype/feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions