Skip to content

Commit

Permalink
chore(example): use maxLength and maximum value (#879)
Browse files Browse the repository at this point in the history
Better demonstrate the capabilities of the swagger Schema annotation
  • Loading branch information
timonback authored Aug 16, 2024
1 parent 8d299ef commit 0600e69
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@NoArgsConstructor
public class AnotherPayloadDto {

@Schema(description = "Foo field", example = "bar", requiredMode = NOT_REQUIRED)
@Schema(description = "Foo field", example = "bar", maxLength = 100, requiredMode = NOT_REQUIRED)
private String foo;

@Schema(description = "Example field", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ExamplePayloadDto {
@Schema(description = "Some string field", example = "some string value", requiredMode = REQUIRED)
private String someString;

@Schema(description = "Some long field", example = "5")
@Schema(description = "Some long field", example = "5", minimum = "0")
private long someLong;

@Schema(description = "Some enum field", example = "FOO2", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"foo": {
"type": "string",
"description": "Foo field",
"maxLength": 100,
"examples": [
"bar"
]
Expand Down Expand Up @@ -188,6 +189,7 @@
"type": "integer",
"description": "Some long field",
"format": "int64",
"minimum": 0,
"examples": [
5
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@NoArgsConstructor
public class AnotherPayloadDto {

@Schema(description = "Foo field", example = "bar", requiredMode = NOT_REQUIRED)
@Schema(description = "Foo field", example = "bar", maxLength = 100, requiredMode = NOT_REQUIRED)
private String foo;

@Schema(description = "Example field", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ExamplePayloadDto {
@Schema(description = "Some string field", example = "some string value", requiredMode = REQUIRED)
private String someString;

@Schema(description = "Some long field", example = "5")
@Schema(description = "Some long field", example = "5", minimum = "0")
private long someLong;

@Schema(description = "Some enum field", example = "FOO2", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class GooglePubSubPayloadDto {
@Schema(description = "Some string field", example = "some string value", requiredMode = REQUIRED)
private String someString;

@Schema(description = "Some long field", example = "5")
@Schema(description = "Some long field", example = "5", minimum = "0")
private long someLong;
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"foo": {
"type": "string",
"description": "Foo field",
"maxLength": 100,
"examples": [
"bar"
]
Expand Down Expand Up @@ -137,6 +138,7 @@
"type": "integer",
"description": "Some long field",
"format": "int64",
"minimum": 0,
"examples": [
5
]
Expand Down Expand Up @@ -170,6 +172,7 @@
"type": "integer",
"description": "Some long field",
"format": "int64",
"minimum": 0,
"examples": [
5
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@NoArgsConstructor
public class AnotherPayloadDto {

@Schema(description = "Foo field", example = "bar", requiredMode = NOT_REQUIRED)
@Schema(description = "Foo field", example = "bar", maxLength = 100, requiredMode = NOT_REQUIRED)
private String foo;

@Schema(description = "Example field", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ExamplePayloadDto {
@Schema(description = "Some string field", example = "some string value", requiredMode = REQUIRED)
private String someString;

@Schema(description = "Some long field", example = "5")
@Schema(description = "Some long field", example = "5", minimum = "0")
private long someLong;

@Schema(description = "Some enum field", example = "FOO2", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"foo": {
"type": "string",
"description": "Foo field",
"maxLength": 100,
"examples": [
"bar"
]
Expand Down Expand Up @@ -104,6 +105,7 @@
"type": "integer",
"description": "Some long field",
"format": "int64",
"minimum": 0,
"examples": [
5
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@NoArgsConstructor
public class AnotherPayloadDto {

@Schema(description = "Foo field", example = "bar", requiredMode = NOT_REQUIRED)
@Schema(description = "Foo field", example = "bar", maxLength = 100, requiredMode = NOT_REQUIRED)
private String foo;

@Schema(description = "Example field", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ExamplePayloadDto {
requiredMode = REQUIRED)
private String someString;

@Schema(description = "Some long field", example = "5")
@Schema(description = "Some long field", example = "5", minimum = "0")
private long someLong;

@Schema(description = "Some enum field", example = "FOO2", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@
"foo": {
"type": "string",
"description": "Foo field",
"maxLength": 100,
"examples": [
"bar"
]
Expand Down Expand Up @@ -948,6 +949,7 @@
"someLong": {
"description": "Some long field",
"format": "int64",
"minimum": 0,
"type": "integer"
},
"someString": {
Expand All @@ -964,6 +966,7 @@
},
"foo": {
"description": "Foo field",
"maxLength": 100,
"type": "string"
}
},
Expand Down Expand Up @@ -994,6 +997,7 @@
"type": "integer",
"description": "Some long field",
"format": "int64",
"minimum": 0,
"examples": [
5
]
Expand Down Expand Up @@ -1034,6 +1038,7 @@
"someLong": {
"description": "Some long field",
"format": "int64",
"minimum": 0,
"type": "integer"
},
"someString": {
Expand Down Expand Up @@ -1106,6 +1111,7 @@
"someLong": {
"description": "Some long field",
"format": "int64",
"minimum": 0,
"type": "integer"
},
"someString": {
Expand Down Expand Up @@ -1968,4 +1974,4 @@
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ components:
foo:
type: string
description: Foo field
maxLength: 100
examples:
- bar
description: Another payload model
Expand Down Expand Up @@ -641,6 +642,7 @@ components:
someLong:
description: Some long field
format: int64
minimum: 0
type: integer
someString:
description: |
Expand All @@ -664,6 +666,7 @@ components:
type: object
foo:
description: Foo field
maxLength: 100
type: string
required:
- example
Expand All @@ -686,6 +689,7 @@ components:
type: integer
description: Some long field
format: int64
minimum: 0
examples:
- 5
someString:
Expand Down Expand Up @@ -731,6 +735,7 @@ components:
someLong:
description: Some long field
format: int64
minimum: 0
type: integer
someString:
description: |
Expand Down Expand Up @@ -796,6 +801,7 @@ components:
someLong:
description: Some long field
format: int64
minimum: 0
type: integer
someString:
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@NoArgsConstructor
public class AnotherPayloadDto {

@Schema(description = "Foo field", example = "bar", requiredMode = NOT_REQUIRED)
@Schema(description = "Foo field", example = "bar", maxLength = 100, requiredMode = NOT_REQUIRED)
private String foo;

@Schema(description = "Example field", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ExamplePayloadDto {
@Schema(description = "Some string field", example = "some string value", requiredMode = REQUIRED)
private String someString;

@Schema(description = "Some long field", example = "5")
@Schema(description = "Some long field", example = "5", minimum = "0")
private long someLong;

@Schema(description = "Some enum field", example = "FOO2", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"foo": {
"type": "string",
"description": "Foo field",
"maxLength": 100,
"examples": [
"bar"
]
Expand Down Expand Up @@ -102,6 +103,7 @@
"someLong": {
"description": "Some long field",
"format": "int64",
"minimum": 0,
"type": "integer"
},
"someString": {
Expand All @@ -118,6 +120,7 @@
},
"foo": {
"description": "Foo field",
"maxLength": 100,
"type": "string"
}
},
Expand Down Expand Up @@ -148,6 +151,7 @@
"type": "integer",
"description": "Some long field",
"format": "int64",
"minimum": 0,
"examples": [
5
]
Expand Down Expand Up @@ -188,6 +192,7 @@
"someLong": {
"description": "Some long field",
"format": "int64",
"minimum": 0,
"type": "integer"
},
"someString": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@NoArgsConstructor
public class AnotherPayloadDto {

@Schema(description = "Foo field", example = "bar", requiredMode = NOT_REQUIRED)
@Schema(description = "Foo field", example = "bar", maxLength = 100, requiredMode = NOT_REQUIRED)
private String foo;

@Schema(description = "Example field", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ExamplePayloadDto {
@Schema(description = "Some string field", example = "some string value", requiredMode = REQUIRED)
private String someString;

@Schema(description = "Some long field", example = "5")
@Schema(description = "Some long field", example = "5", minimum = "0")
private long someLong;

@Schema(description = "Some enum field", example = "FOO2", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"foo": {
"type": "string",
"description": "Foo field",
"maxLength": 100,
"examples": [
"bar"
]
Expand Down Expand Up @@ -112,6 +113,7 @@
"type": "integer",
"description": "Some long field",
"format": "int64",
"minimum": 0,
"examples": [
5
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@NoArgsConstructor
public class AnotherPayloadDto {

@Schema(description = "Foo field", example = "bar", requiredMode = NOT_REQUIRED)
@Schema(description = "Foo field", example = "bar", maxLength = 100, requiredMode = NOT_REQUIRED)
private String foo;

@Schema(description = "Example field", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ExamplePayloadDto {
@Schema(description = "Some string field", example = "some string value", requiredMode = REQUIRED)
private String someString;

@Schema(description = "Some long field", example = "5")
@Schema(description = "Some long field", example = "5", minimum = "0")
private long someLong;

@Schema(description = "Some enum field", example = "FOO2", requiredMode = REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"foo": {
"type": "string",
"description": "Foo field",
"maxLength": 100,
"examples": [
"bar"
]
Expand Down Expand Up @@ -153,6 +154,7 @@
"type": "integer",
"description": "Some long field",
"format": "int64",
"minimum": 0,
"examples": [
5
]
Expand Down

0 comments on commit 0600e69

Please sign in to comment.