fix: use `.String()` method for making a string from uuid
fixes #1914
@MilkeeyCat You can achieve a similar solution using by overriding the property type in overlay.yaml
This PR looks good! I have successfully tested this on my local environment, and it works as expected.
It would be even better if you could add or update a test.
For example, you might want to consider adding a paths in:
file: internal/test/schemas/schemas.yaml
line: 150
content:
/issues/1914:
post:
operationId: Issue1914
description: |
Ensure that anonymous inner types are generated correctly.
requestBody:
content:
text/plain:
schema:
type: string
format: uuid
and then run make generate on this repository root.
Thanks!
Looking at this, I'm wondering if we should put in a wider fix, which is that we try and convert the type to a string i.e. with fmt.Sprintf or something similar, so we end up returning something rather than hitting the compilation error - thoughts?
so we end up returning something rather than hitting the compilation error - thoughts?
Hm, honestly I prefer compilation error over incorrectly stringified value
Hmm - I get your thinking, but also not sure :thinking: I've raised https://github.com/oapi-codegen/oapi-codegen/pull/1975 in the meantime, let's see what some others think about the behaviour :+1:
Maybe let's add a compatibility-option to disable the fallback?
I don't understand what fallback you're talking about, but #1975 looks good to me
Thanks - so I'm thinking we could add an entry into the CompatibilityOptions to allow us to push #1975 through as-is, but allow folks to opt-in to "I want to have a compilation error when there's not a String() method on the type" which would be best of both worlds?
With the way #1975 is done I personally don't think this option is needed.
... allow folks to opt-in to "I want to have a compilation error when there's not a String() method on the type"
How would that work with integer, string types? They don't have .String() method
With the way #1975 is done I personally don't think this option is needed.
... allow folks to opt-in to "I want to have a compilation error when there's not a String() method on the type"
How would that work with integer, string types? They don't have
.String()method
Ah yeah, so we'd probably have the fallback of "if someone's using the compatibility option for the fallback, use string(body), and if they're not, use fmt.Sprintf(...)"