OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
We would like to use org.bson.types.ObjectId type to reference elements in an array:
BulkUpdateErpOrderNumberDto:
type: object
description: List of replenishment process IDs for which a new ERP order number should be set
properties:
erpOrderNumber:
type: string
maxLength: 50
description: SAP (ERP) order number
example: ERP58207
rpIds:
type: array
uniqueItems: true
minItems: 1
items:
$ref: '#/components/schemas/ObjectId'
description: Replenishment process IDs
example: [ 662760d01aad920e6773c164, 662762491aad920e6773c166 ]
required:
- rpIds
# Mapped to the Mongo ObjectId object
ObjectId:
type: object
description: ObjectId value
example: 64a55f3ad5804f0f591b9375
The problem is that generated code tries to validate external mapped types. The generated code can't be compiled because
org.bson.types.ObjectId can't be validated (Set<@Valid org.bson.types.ObjectId>)
@Schema(name = "BulkUpdateErpOrderNumberDto", description = "List of replenishment process IDs for which a new ERP order number should be set")
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.6.0")
public class BulkUpdateErpOrderNumberDto {
private String erpOrderNumber;
@Valid
private Set<@Valid org.bson.types.ObjectId> rpIds = new LinkedHashSet<>();
public BulkUpdateErpOrderNumberDto() {
super();
}
/**
* Constructor with only required parameters
*/
public BulkUpdateErpOrderNumberDto(Set<@Valid org.bson.types.ObjectId> rpIds) {
this.rpIds = rpIds;
}
}
@Valid annotation shouldn't be added when object is mapped in pom.xml file.
Note that if refer ObjectId with objectId like this:
[WARNING] Unknown type found in the schema: objectId. To map it, please use the schema mapping option (e.g. --schema-mappings in CLI)
But generated code is correct:
@Schema(name = "BulkUpdateErpOrderNumberDto", description = "List of replenishment process IDs for which a new ERP order number should be set")
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.6.0")
public class BulkUpdateErpOrderNumberDto {
private String erpOrderNumber;
@Valid
private Set<org.bson.types.ObjectId> rpIds = new LinkedHashSet<>();
public BulkUpdateErpOrderNumberDto() {
super();
}
/**
* Constructor with only required parameters
*/
public BulkUpdateErpOrderNumberDto(Set<org.bson.types.ObjectId> rpIds) {
this.rpIds = rpIds;
}
}
Description
We use Maven openAPI generator plugin version 7.6.0 with following settings:
We would like to use
org.bson.types.ObjectId
type to reference elements in an array:The problem is that generated code tries to validate external mapped types. The generated code can't be compiled because
org.bson.types.ObjectId
can't be validated (Set<@Valid org.bson.types.ObjectId>
)@Valid
annotation shouldn't be added when object is mapped inpom.xml
file.Note that if refer
ObjectId
withobjectId
like this:It works with a warning:
But generated code is correct:
Of course the OpenAPI specification is not valid![Screenshot 2024-06-24 at 14 32 34](https://github.com/OpenAPITools/openapi-generator/assets/2969871/e7a1d773-d9a4-448f-aeba-8f58196ffbdf)