In template "context" param with "requestBodies" value is empty
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?
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