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

In template "context" param with "requestBodies" value is empty #148

Open
StasanTelnov opened this issue Apr 5, 2019 · 1 comment
Open

Comments

@StasanTelnov
Copy link

Hello.
Sorry for my stupid questions, you already tired of them.
But such limited documentation is hard to figure out.

I want to split requests and responses models to different folders.
For example, I have request in YAML:

paths:
  /content/city:
    post:
      summary: Find city
      description: Find city in specific country by query string
      tags:
        - Content
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/City'
      requestBody:
        $ref: '#/components/requestBodies/Location'

and components:

components:
  requestBodies:
    Location:
      description: Location request model
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              query:
                type: string
              count:
                type: integer

  schemas:
    City:
      type: object
      required:
        - city_id
      properties:
        city_id:
          type: integer
        name:
          type: string

And in template I have rules:

  - path: Sources/ModelRequest.swift
    context: requestBodies
    destination: "Sources/Models/Request/{{ type }}test.swift"
    
  - path: Sources/ModelResponse.swift
    context: schemas
    destination: "Sources/Models/Response/{{ type }}.swift"

Responses models is OK. But I dont have requests models (zero files in Sources/Models/Request/).
I found, that requestBodies is resolving in https://github.com/yonaskolb/SwagGen/blob/77586ddd462635e5fe3ce0eacdec8c7a9aee8443/Sources/Swagger/Component/ComponentResolver.swift (25 and 27 lines is duplicated).
I try comment "context" and send raw in ModelRequest.swift and in .stencil file I can found requests properties:

{% for temp in raw.components.requestBodies %}

//
{{ raw.components.requestBodies[temp].content['application/json'].schema }}
{% endfor %}

But it is very bad solution. What I doing incorrect?
How I can access to components/requestBodies schema properties and type as well as components/schemas properties and type? What "context" is correct in template.yml file for this?

@yonaskolb
Copy link
Owner

requestBodies isn't currently provided as a top level property for the template to use. Request bodies are a new thing in Swagger 3, and adding it as a stencil context, slipped under the radar. It can be added here, if you'd like to open a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants