Generate anonymous objects referenced in schemas#648
Generate anonymous objects referenced in schemas#648jamietanna wants to merge 8 commits intooapi-codegen:mainfrom
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.
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.
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 |
|
Another bump for this. |
|
Hey @jamietanna do you have any news for this feature ? We would benefit a lot from this and would like to see it merge. Do you have any blockers ? Cheers |
Main blocker is time to be honest 😅 As noted in #1606 the project would appreciate sponsors to help with dedicating time to the project's maintenance, and if the company you're working at would benefit from this, I'd appreciate sponsorship to help the work along I've got quite a few things to do before v2.5.0 and an ever growing backlog, on top of long standing issues like this that would benefit many users |
Closes #626, #636.