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

new: Use enum type for all unit enums. #75

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

#### 🚀 Updates

- Updated enums with all unit variants to use the `Enum` schema type, instead of the `Union` schema
type. Enums that mix and match unit with other variants will to continue to use `Union`, and will
respect serde tagging.

#### ⚙️ Internal

- Reworked dependencies and features so that some dependencies only enable when a feature is
Expand Down
7 changes: 7 additions & 0 deletions crates/config/src/schema/renderers/json_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,14 @@ impl SchemaRenderer<Schema> for JsonSchemaRenderer {
};
}

let metadata = Metadata {
title: enu.name.clone(),
description: enu.description.clone().map(clean_comment),
..Default::default()
};

Ok(Schema::Object(SchemaObject {
metadata: Some(Box::new(metadata)),
instance_type: Some(SingleOrVec::Single(Box::new(instance_type))),
enum_values: Some(enum_values),
..Default::default()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ expression: "fs::read_to_string(file).unwrap()"
"additionalProperties": false
},
"BasicEnum": {
"title": "BasicEnum",
"type": "string",
"enum": [
"foo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,43 +157,11 @@ expression: "std::fs::read_to_string(file).unwrap()"
},
"AllUnit": {
"title": "AllUnit",
"anyOf": [
{
"type": "object",
"required": [
"foo"
],
"properties": {
"foo": {
"const": "foo"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"bar"
],
"properties": {
"bar": {
"const": "bar"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"baz"
],
"properties": {
"baz": {
"const": "baz"
}
},
"additionalProperties": false
}
"type": "string",
"enum": [
"foo",
"bar",
"baz"
]
},
"AllUnnamed": {
Expand Down Expand Up @@ -405,47 +373,6 @@ expression: "std::fs::read_to_string(file).unwrap()"
}
]
},
"PartialAllUnit": {
"title": "PartialAllUnit",
"anyOf": [
{
"type": "object",
"required": [
"foo"
],
"properties": {
"foo": {
"const": "foo"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"bar"
],
"properties": {
"bar": {
"const": "bar"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"baz"
],
"properties": {
"baz": {
"const": "baz"
}
},
"additionalProperties": false
}
]
},
"PartialAllUnnamed": {
"title": "PartialAllUnnamed",
"anyOf": [
Expand Down Expand Up @@ -713,48 +640,6 @@ expression: "std::fs::read_to_string(file).unwrap()"
}
]
},
"PartialWithComments": {
"title": "PartialWithComments",
"description": "Container",
"anyOf": [
{
"type": "object",
"required": [
"foo"
],
"properties": {
"foo": {
"const": "foo"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"bar"
],
"properties": {
"bar": {
"const": "bar"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"baz"
],
"properties": {
"baz": {
"const": "baz"
}
},
"additionalProperties": false
}
]
},
"PartialWithSerde": {
"title": "PartialWithSerde",
"anyOf": [
Expand Down Expand Up @@ -816,43 +701,11 @@ expression: "std::fs::read_to_string(file).unwrap()"
"WithComments": {
"title": "WithComments",
"description": "Container",
"anyOf": [
{
"type": "object",
"required": [
"foo"
],
"properties": {
"foo": {
"const": "foo"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"bar"
],
"properties": {
"bar": {
"const": "bar"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"baz"
],
"properties": {
"baz": {
"const": "baz"
}
},
"additionalProperties": false
}
"type": "string",
"enum": [
"foo",
"bar",
"baz"
]
},
"WithSerde": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ expression: "std::fs::read_to_string(file).unwrap()"

/* eslint-disable */

export type AllUnit = {
foo: 'foo';
} | {
bar: 'bar';
} | {
baz: 'baz';
};
export type AllUnit = 'foo' | 'bar' | 'baz';

export type AllUnnamed = {
foo: string;
Expand Down Expand Up @@ -43,13 +37,7 @@ export type NestedConfigs = {

export type WithSerde = string | boolean | number;

export type WithComments = {
foo: 'foo';
} | {
bar: 'bar';
} | {
baz: 'baz';
};
export type WithComments = 'foo' | 'bar' | 'baz';

export type Untagged = null | boolean | [number, string] | SomeConfig;

Expand Down Expand Up @@ -79,14 +67,6 @@ export type AdjacentTagged = {
content: SomeConfig;
};

export type PartialAllUnit = {
foo: 'foo';
} | {
bar: 'bar';
} | {
baz: 'baz';
};

export type PartialAllUnnamed = {
foo: string;
} | {
Expand Down Expand Up @@ -116,14 +96,6 @@ export type PartialNestedConfigs = {

export type PartialWithSerde = string | boolean | number;

export type PartialWithComments = {
foo: 'foo';
} | {
bar: 'bar';
} | {
baz: 'baz';
};

export type PartialUntagged = null | boolean | [number, string] | PartialSomeConfig;

export type PartialExternalTagged = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ expression: "std::fs::read_to_string(file).unwrap()"
"additionalProperties": false,
"definitions": {
"Aliased": {
"title": "Aliased",
"type": "string",
"enum": [
"foo",
Expand All @@ -59,6 +60,7 @@ expression: "std::fs::read_to_string(file).unwrap()"
]
},
"BasicEnum": {
"title": "BasicEnum",
"type": "string",
"enum": [
"foo",
Expand Down Expand Up @@ -362,6 +364,7 @@ expression: "std::fs::read_to_string(file).unwrap()"
"additionalProperties": false
},
"OtherEnum": {
"title": "OtherEnum",
"type": "string",
"enum": [
"foo",
Expand Down Expand Up @@ -751,6 +754,7 @@ expression: "std::fs::read_to_string(file).unwrap()"
"additionalProperties": false
},
"SomeEnum": {
"title": "SomeEnum",
"type": "string",
"enum": [
"a",
Expand All @@ -759,6 +763,7 @@ expression: "std::fs::read_to_string(file).unwrap()"
]
},
"Test": {
"title": "Test",
"type": "string",
"enum": [
"FOO",
Expand Down
Loading
Loading