aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

Api inline swagger with $ref to external file #1901

Open chestongo opened 4 years ago

chestongo commented 4 years ago

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.

ShreyaGangishetty commented 4 years ago

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

c2tarun commented 4 years ago

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

chestongo commented 4 years ago
├── 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.