Skip to content
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

[#211] Generate OpenAPI dictionaries without fixed keys as maps #424

Merged

Conversation

natsukagami
Copy link
Contributor

Closes #211.

Generate all objects with the additionalProperties value set, but no properties set as maps.

For example, these schemas:

anyMap:
    type: object
    additionalProperties: true
numberMap:
    type: object
    additionalProperties:
        type: integer
mapWithFixedKeys:
    type: object
    additionalProperties:
        type: string
    properties:
        key:
            type: string

produces the following

type AnyMap map[string]interface{}

type NumberMap map[string]int

type MapWithFixedKeys struct {
    Key                  string
    AdditionalProperties map[string]string
}

instead of

type AnyMap struct {
    AdditionalProperties map[string]interface{}
}

type NumberMap struct {
    AdditionalProperties map[string]int
}

type MapWithFixedKeys struct {
    Key                  string
    AdditionalProperties map[string]string
}

This is a small breaking change.

"dictionary-like" means an object with additional properties
(`additionalProperties: true` or `additionalProperties: {...}`),
but comes with no other properties.

Note that the `HasAdditionalProperties` value is also set to false,
as the Go type is no longer an object.

This is a breaking change.
@deepmap-marcinr
Copy link
Contributor

Sorry to take so long to get to this.

Would you mind adding a configuration option for old schema behavior in the new Configuration struct, and allow disabling this new behavior? I guess we could call it "DisableFlattenAdditionalProperties" or something liek that - so that your new behavior is the default, but we can override it off. I'd be happy to merge this.

@deepmap-marcinr
Copy link
Contributor

If not, I can take care of it, but I'm not entirely sure how to do it in github so you get a commit credit :)

@natsukagami
Copy link
Contributor Author

Please take care of it. It's been a long time since I touched the codebase, I am no longer familiar with it.

As for the commit credit, I think as long as you merge or squash with the "Co-author" fields in the commit message intact GitHub will treat it well :P

@deepmap-marcinr deepmap-marcinr merged commit 804ca62 into deepmap:master Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

infer map from additionalProperties
2 participants