Skip to content

OpenAPI: Move to oneOf for the types#4899

Merged
rdblue merged 1 commit intoapache:masterfrom
Fokko:fd-move-to-oneOf
May 30, 2022
Merged

OpenAPI: Move to oneOf for the types#4899
rdblue merged 1 commit intoapache:masterfrom
Fokko:fd-move-to-oneOf

Conversation

@Fokko
Copy link
Contributor

@Fokko Fokko commented May 30, 2022

All the types match exactly one of the schemas:

# PrimitiveType
"string"

# StructType
{"type": "struct", ...}

# ListType
{"type": "list", ...}

# MapType
{"type": "map", ...}

For more information:
https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/

The types are mutually exclusive (in the schema, technically an int can also be promoted to a long). The aforementioned types should map to exactly one type.

We could also add a discriminator if we bump the primitive type to an object as well. My suggestion would be to break down:

"fixed[22]"

# and

"string"

into

{"type": "fixed", "size": 22}

# and

{"type": "string"}

This would allow us to set:

    Type:
      oneOf:
        - $ref: '#/components/schemas/PrimitiveType'
        - $ref: '#/components/schemas/StructType'
        - $ref: '#/components/schemas/ListType'
        - $ref: '#/components/schemas/MapType'
      discriminator:
        propertyName: type

This way the OpenAPI spec also defines how to distinguish the different types.

All the types match exactly one of the schemas:

```json
"string"

{"type": "struct", ...}

{"type": "list", ...}

{"type": "map", ...}
```

For more information:
https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/

We could also add a discriminator if we bump the primitive type
to an object as well. My suggestion would be to break down:

```json
"fixed[22]"
```

into

```json
{"type": "fixed", "length": 22}
```

This would allow us to set:

```yaml
    Type:
      oneOf:
        - $ref: '#/components/schemas/PrimitiveType'
        - $ref: '#/components/schemas/StructType'
        - $ref: '#/components/schemas/ListType'
        - $ref: '#/components/schemas/MapType'
      discriminator:
        propertyName: type
```

This way the OpenAPI spec also defines how to
distinguish the different types.
@rdblue rdblue merged commit 2de91b6 into apache:master May 30, 2022
@rdblue
Copy link
Contributor

rdblue commented May 30, 2022

Thanks, @Fokko! I agree it is more clear this way.

@Fokko Fokko deleted the fd-move-to-oneOf branch May 30, 2022 17:20
@Fokko Fokko added the OPENAPI label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants