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
Generate anonymous objects referenced in schemas #648
base: master
Are you sure you want to change the base?
Conversation
I am very interested to try it, when it is finished, as I think it is solving a similar issue I am experiencing... 👍 |
Hi guys, I was wondering if there was any update on that issue ? |
31b8bcd
to
c0a2c50
Compare
@deepmap-marcinr I think I may need a hand with the |
9ef3dd1
to
52a07d9
Compare
I've got this working finally 👏 If you're happy with it, @deepmap-marcinr, I'll sort out the Git history then merge it. I'll test it out with a few other specs that have been mentioned to be affected, too |
Got a couple of tweaks to make:
|
b4f4d67
to
698edfe
Compare
rew! handle absent content/mediaType
As part of future changes we need to be able to reference all the types in the defined `responses` of a specification. However, as we're currently only rendering `application/json` media types, this fails. Instead, we can generate `json.RawMessage` (which is an alias of `[]byte`) for these types, which allow referencing them, and (un)marshaling data to the types.
As part of future changes we need to be able to reference all the types in the defined `requestBodies` of a specification. However, as we're currently only rendering `application/json` media types, this fails. Instead, we can generate `json.RawMessage` (which is an alias of `[]byte`) for these types, which allow referencing them, and (un)marshaling data to the types.
698edfe
to
1772661
Compare
Previously, there was no way to render any anonymous types that are referenced in the `paths` of an OpenAPI specification. Although there is a strong preference in the community to use the `/components/schemas/`, there are times that it's out of our control to move objects around. This generates both the `requestBody` and `responses`. TODO Closes 626 TODO
1772661
to
aa7cfee
Compare
} else { | ||
typeName += ToCamelCase(strings.ToLower(operationName)) + ToCamelCase(pathName) | ||
} | ||
typeName += fmt.Sprintf("ResponseBody%s", ToCamelCase(statusCodeOrDefault)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this sufficient to avoid type conflict? What if a request has two response bodies with different content types for the same response code? What happens in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, yep, it'll handle the conflict well enough
i.e.:
// NewPetResponseBody200ApplicationYaml defines model for the response body for POST /pets (200, application/yaml).
type NewPetResponseBody200ApplicationYaml = map[string]interface{}
// NewPetResponseBody200TextPlain defines model for the response body for POST /pets (200, text/plain).
type NewPetResponseBody200TextPlain = map[string]interface{}
Bump |
Is there any updated on this? Simplifying the issue, we have this generated code:
when running
By trying a few different combinations, it appears that the anonymoust |
Closes #626, #636.