swagger-api / swagger-api/swagger-codegen
Accessing $ref properties within another property in a model.mustache template?
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I am a beginner with Swagger Codegen. I am creating a custom generator. Let's say I have two models in my swagger.json file, one of which has a property which references the other model. I would like to access the properties of the accessed model through the property that is referencing it in my model.mustache file.
Is it possible for a property to have properties of its own, and if so, is it possible to access them in the model.mustache file?
Here is an example of what I mean:
Swagger declaration file content or url
```json
"definitions": {
"Object1": {
"properties": {
"testInteger": {
"description": "An integer value.",
"type": "integer"
}
},
"type": "object"
},
"Object2": {
"properties": {
"anotherTestInteger": {
"$ref": "#/definitions/Object1"
}
},
"type": "object"
}
}
```
What I'd like to be able to do with the model.mustache file is something like this:
{{#models}}
{{#model}}
Looking at the Object2 model
{{#vars}}
This is the name of the property from Object2: {{name}}
{{#refVars}}
This is a property of the property from Object2: {{name}}
{{/refVars}}
{{/vars}}
{{/model}}
{{/models}}
So I'd like to be able to print Object1's properties in the model file for Object2. Unfortunately I can't change the spec that I'm using. Is there a way to do this with mustache, or would it be best for me to just edit my codegen.java file?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the model.mustache example and the referenced swagger.json definitions, then inspect the generator path mentioned as codegen.java to see what data is exposed for referenced properties. Done means establishing whether nested $ref properties are available to Mustache templates and documenting the supported approach or the generator changes required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100