aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Api inline swagger with $ref to external file

Open chestongo opened this issue 4 years ago • 3 comments

I want to use an additional external swagger file in my swagger.yaml file.

ServerlessApi:
  Type: AWS::Serverless::Api
  Properties:
    DefinitionBody:
      Fn::Transform:
        Name: AWS::Include
        Parameters:
          Location: ../../api/swagger.yaml
paths:
  /company:
    $ref: ./routes/company/swagger.yaml

How can I do this using SAM? SAM doesn't upload the additional file.

chestongo avatar Mar 26 '20 02:03 chestongo

@chestongo SAM currently uploads original swagger files and doesn't import additional swagger files. Transferring to aws-sam-cli

ShreyaGangishetty avatar Mar 27 '20 18:03 ShreyaGangishetty

Can you please share your folder structure? As in where are you keeping the additional swagger file?

c2tarun avatar Apr 08 '20 17:04 c2tarun

├── api
│   ├── swagger.yaml
├── events
│   └── event.json
├── handlers
│   ├── company
│   │   ├── get
│   │   │   └── index.js
│   │   └── post
│   │       └── index.js
│   └── dynamodb
│       └── custom
│           └── index.js
├── libraries
│   ├── nodejs
│   │   ├── node_modules
├── samconfig.toml
├── template.yaml
└── templates
    ├── apigateway
    │   └── template.yaml
    ├── dynamodb
    │   └── template.yaml
    ├── iam
    │   ├── policy
    │   │   └── template.yaml
    │   └── role
    │       └── template.yaml
    ├── lambda
    │   ├── function
    │   │   └── template.yaml
    │   ├── layer
    │   │   └── template.yaml
    │   └── permission
    │       └── template.yaml
    ├── s3
    │   └── template.yaml
    └── swagger
        └── template.yaml

But what i want is:

├── api
│   ├── models
│   │   ├── car
│   │   │   └── swagger.yaml
│   │   ├── company
│   │   │   └── swagger.yaml
│   │   ├── empty
│   │   │   └── swagger.yaml

--- etc ---

│   ├── routes
│   │   ├── car
│   │   │   └── swagger.yaml
│   │   ├── company
│   │   │   └── swagger.yaml

--- etc ---

│   ├── swagger.yaml
│   └── templates
│       └── swagger.yaml

However, from @ShreyaGangishetty reply, it is currently not possible. If you have many api endpoints, with configurations, you have to store all the definitions in one huge swagger file.

chestongo avatar Apr 12 '20 00:04 chestongo