openapi3: support format conditional on doc.openapi version#744
openapi3: support format conditional on doc.openapi version#744cboitel wants to merge 5 commits intogetkin:masterfrom
doc.openapi version#744Conversation
3301b24 to
ab2416b
Compare
|
@fenollp finally made up with implementing a string format support based on OpenAPI minor version |
fenollp
left a comment
There was a problem hiding this comment.
Hey! Thanks for this. This is going to the right direction. I mostly have comments on the API design.
| func (format *Format) add(minMinorVersion uint64, vFormat *versionedFormat, override bool) { | ||
| if format != nil { | ||
| if format.versionedFormats == nil { | ||
| format.versionedFormats = make([]*versionedFormat, minMinorVersion+1) |
There was a problem hiding this comment.
This is allocating a lot of unused space. I'd rather you use a dynamically-sized map. Use an additional slice for ordered map keys.
There was a problem hiding this comment.
Did that so it is very fast to determine format to use for a specific minor version when validating.
Since number of minor versions won't be too big, I don't think this can be an memory issue.
| return nil | ||
| } | ||
|
|
||
| func (format Format) DefinedForMinorVersion(minorVersion uint64) bool { |
There was a problem hiding this comment.
Will have to determine if we keep it so one can determine if a definition already exists for a specific minor version. Since format does not expose its content, this is the only way for one to know about it.
If we keep, I will need to add tests
|
|
||
| // DefineStringFormatStartingWithOpenAPIMinorVersion defines a new regexp pattern for a given format to apply for a minor version of OpenAPI 3 | ||
| // override allows to enforce regex usage to all subsequent minor versions of OpenAPI | ||
| func DefineStringFormatStartingWithOpenAPIMinorVersion(name string, fromMinorVersion uint64, pattern string, override bool) { |
There was a problem hiding this comment.
Why uint64? uint8 or even uint16 is large enough.
I like the idea but I'd rather have a simpler API:
- a shorter method such as the existing
DefineStringFormat(extend with variadic args) - make
override=truethe only behavior. API users will simply make multiple calls to cut specific ranges - turn
fromMinorVersioninto afloat(f32if for allY,3.Ycan be expressed and I believe it's a yes) so users can seeDefineStringFormat(name, pattern, 3.1). The call should panic on non-nil non-floats and compare minors with a0.4epsilon.
There was a problem hiding this comment.
(yes, I'm asking to extend the existing 2 methods with a variadic float)
There was a problem hiding this comment.
uint64 comes from the string parsing function used when parsing OpenAPI document
=> Go string parsing returns a uint64
=> Casting to uint8 would require minor version
Since most processors are 64 bits, using an uint8/uint64 does save memory nor it brings performance gain.
There was a problem hiding this comment.
Gone with the variadic options. have a look
| func TestStringFormatsStartingWithOpenAPIMinorVersion(t *testing.T) { | ||
| DefineStringFormatStartingWithOpenAPIMinorVersion("test", 0, "test0", false) | ||
| for i := uint64(0); i < 10; i++ { | ||
| if assert.Contains(t, SchemaStringFormats, "test") && |
There was a problem hiding this comment.
Please prefer the require package over assert. This makes for fewer nesting.
|
|
||
| customizeMessageError func(err *SchemaError) string | ||
|
|
||
| openapiMinorVersion uint64 // defaults to 0 (3.0.z) |
There was a problem hiding this comment.
see discussion earlier
| } | ||
|
|
||
| // MinorVersion returns minor version from string assuming 0 is the default | ||
| func (oai Version) Minor() uint64 { |
There was a problem hiding this comment.
uint64 seems too big. Also why not return the two possible errors? (or edit func doc)
There was a problem hiding this comment.
I see you introduced this for use by the schema validation settings. Let's return a float then :)
| const FormatOfStringForUUIDOfRFC4122 = `^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$` ... | ||
| const SerializationSimple = "simple" ... | ||
| var SchemaErrorDetailsDisabled = false ... | ||
| var ErrInvalidVersion ... |
There was a problem hiding this comment.
What's your rationale to export this?
There was a problem hiding this comment.
So one can check at loading time he got an invalid error version, not some other kind of error.
doc.openapi version
|
@cboitel Hey there. Do you need help moving this forward? |
|
Nope. Just missed it while I was on vacations. Will get back to it next week. |
6855e99 to
bb0e0e5
Compare
|
I had a hard time to rebase. Finally found it was related to some new/existing tests defining string formats for uuid but not restoring string formats to original value. I created a new Save/Restore/RestoreDefault functions for string formats so one can easily do that like we need in our tests. I will now address your earlier comments in the upcoming days. |
eaa7245 to
0e202c6
Compare
0e202c6 to
355d474
Compare
Implements string format improvements in issue #582 with openapi minor version support.