[Enhancement] added support for custom type & format mapping#9285
Merged
[Enhancement] added support for custom type & format mapping#9285
Conversation
5 tasks
Contributor
Shouldn't it be |
Member
Author
|
@marcelstoer yes, just corrected it. thanks for pointing it out. |
|
I'm trying to wrap my head around this, hope anyone can help me. Thanks for all the work btw. Does this imply that I can define my own type like: url:
type: string
format: url
pattern: $someURLPattern... and then reference this type by using the type+format syntax? I would love a solution for our workaround with YAML anchors and/or $refs where we defined a custom type. |
Contributor
|
This is how I use "custom types" but it's unrelated to formats. common-types.yaml components:
schemas:
Uuid:
type: string
description: |
Canonical textual representation of the 32 hexadecimal (base-16) UUID digits, displayed in five groups
separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters
minLength: 36
maxLength: 36
pattern: '^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$'some API contract ...
Branch:
type: object
required:
- id
properties:
id:
$ref: 'path-to/common-types.yaml#/components/schemas/Uuid'
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on #4931 (credits: @ShoeBoom) but use
+as the separator=========================
Makes it possible to map format.
For example these args can be used to properly map the following:
generate -i openapi.json -o out -g kotlin --type-mappings integer+byte=kotlin.ByteBy default it would map
footoIntthis is similar to #2730
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.For Windows users, please run the script in Git BASH.
master,5.1.x,6.0.xcc @OpenAPITools/generator-core-team