Comments (3)
Nevermind, just missed it in the docs:
{
classTransformerMetadataStorage: defaultMetadataStorage,
}
from class-validator-jsonschema.
I'm having a similar issue. Even though I set up metadata storage it still returns "$ref": "#/definitions/Child"
instead of "$ref": "#/components/schemas/Child"
.
Here's the code:
import { validationMetadatasToSchemas } from 'class-validator-jsonschema';
import { defaultMetadataStorage } from 'class-transformer/storage';
const schemas = validationMetadatasToSchemas({
classTransformerMetadataStorage: defaultMetadataStorage,
});
import { ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
class Child {
name: string;
}
class BadRequestValidationError {
@ValidateNested({each: true})
@Type(() => Child)
children!: Child[];
@ValidateNested()
@Type(() => Child)
child!: Child;
}
The above definitions generated the following BadRequestValidationError
schema:
{
"properties": {
"children": {
"items": {
"$ref": "#/definitions/Child"
},
"type": "array"
},
"child": {
"$ref": "#/definitions/Child"
}
},
"type": "object",
"required": [
"children",
"child"
]
}
Logging defaultMetadataStorage
content gives me the following output:
MetadataStorage {
_typeMetadatas: Map(1) {
[Function: BadRequestValidationError] => Map(2) { 'children' => [TypeMetadata], 'child' => [TypeMetadata] }
},
_transformMetadatas: Map(0) {},
_exposeMetadatas: Map(0) {},
_excludeMetadatas: Map(0) {},
_ancestorsMap: Map(0) {}
}
Maybe there has been some breaking changes to class-transformer
? Am I missing something?
@epiphone any ideas?
from class-validator-jsonschema.
Couple of things:
Child
class must have at least one class-validator decorator for it to get registered in class-transformer'sdefaultMetadataStorage
refPointerPrefix
property must be defined if you want to use reference paths of#/components/schemas
instead of the default#/definitions
https://github.com/epiphone/routing-controllers-openapi#validation-classes
I've updated the sample project to demonstrate nested validation, please check out epiphone/routing-controllers-openapi@bea6f3d.
from class-validator-jsonschema.
Related Issues (20)
- Regression bug validationMetadatasToSchemas v5.0.0 HOT 7
- Mixed array of custom type
- Incorrectly generated schema for subclasses HOT 2
- Don't use refs for nested objects HOT 3
- Cannot find module 'class-transformer/metadata/MetadataStorage' HOT 1
- Validation Groups Feature HOT 1
- class-transformer package is missing as npm dependency HOT 1
- How to get jsonschema for only one class ? HOT 10
- Can you convert from JSON back to class? HOT 1
- Regular expression for IS_DATE_STRING is missing escape characters HOT 1
- Typescript build failing HOT 1
- @isEnum "type": "string"
- Reflect.getMetadata is not a function when using @Type nested property type HOT 1
- Support for Fastify or Fastify-Swagger
- Bug with decorator `@Exclude` processing on classes inheritance HOT 1
- Regular expression for IS_DATE_STRING is missing escape characters
- class-transformer version mismatch HOT 1
- Move inherited properties before sub class properties
- Error with latest version of node
- class transformer discriminators
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from class-validator-jsonschema.