aws-sam-cli
aws-sam-cli copied to clipboard
Api inline swagger with $ref to external file
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 SAM currently uploads original swagger files and doesn't import additional swagger files. Transferring to aws-sam-cli
Can you please share your folder structure? As in where are you keeping the additional swagger file?
├── 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.