You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
openapi: '3.0.3'info:
version: 1.0.0title: Swaggerservers:
- url: /v1paths:
/discriminator_implied:
post:
description: Creates a new pet in the store.requestBody:
description: Pet to add to the storerequired: truecontent:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/CatObject'
- $ref: '#/components/schemas/DogObject'discriminator:
propertyName: pet_typeresponses:
'200':
description: Updated/pets:
post:
description: Creates a new pet in the store.requestBody:
description: Pet to add to the storerequired: truecontent:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/CatObject'
- $ref: '#/components/schemas/DogObject'discriminator:
propertyName: pet_typemapping:
cat: '#/components/schemas/CatObject'kitty: '#/components/schemas/CatObject'dog: '#/components/schemas/DogObject'puppy: '#/components/schemas/DogObject'responses:
'200':
description: Updated/pets_all:
post:
description: Creates a new pet in the store.operationId: createPetAllx-eov-operation-id: pets#create ## overrides operationIdx-eov-operation-handler: api/controllers/petsrequestBody:
description: Pet to add to the storerequired: truecontent:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'discriminator:
propertyName: pet_typeresponses:
'200':
description: Updatedcomponents:
schemas:
DogObject:
type: objectrequired:
- bark
- breed
- pet_typeproperties:
bark:
type: booleanbreed:
type: stringenum: [Dingo, Husky, Retriever, Shepherd]pet_type:
type: stringenum: [dog, puppy]CatObject:
type: objectrequired:
- hunts
- age
- pet_typeproperties:
hunts:
type: booleanage:
type: integerpet_type:
type: stringenum: [cat, kitty]Pet:
type: objectrequired:
- pet_typeproperties:
pet_type:
type: stringdiscriminator:
propertyName: pet_typeDog: # "Dog" is a value for the pet_type property (the discriminator value)allOf: # Combines the main `Pet` schema with `Dog`-specific properties
- $ref: '#/components/schemas/Pet'
- type: object# all other properties specific to a `Dog`properties:
bark:
type: booleanbreed:
type: stringenum: [Dingo, Husky, Retriever, Shepherd]Cat: # "Cat" is a value for the pet_type property (the discriminator value)allOf: # Combines the main `Pet` schema with `Cat`-specific properties
- $ref: '#/components/schemas/Pet'
- type: object# all other properties specific to a `Cat`properties:
hunts:
type: booleanage:
type: integer
import*aspathfrom'path';import{expect}from'chai';import*asrequestfrom'supertest';import{createApp}from'./common/app';import*aspackageJsonfrom'../package.json';describe('one.of.2.spec',()=>{letapp=null;before(async()=>{constapiSpec=path.join('test','resources','one.of.2.yaml');app=awaitcreateApp({ apiSpec },3005,(app)=>{app.post(`${app.basePath}/discriminator_implied`,(req,res)=>res.json(req.body),);app.post(`${app.basePath}/pets`,(req,res)=>{res.json(req.body);});app.post(`${app.basePath}/pets_all`,(req,res)=>{res.json(req.body);});app.use((err,req,res,next)=>{console.error(err);res.status(err.status??500).json({message: err.message,code: err.status??500,});});},false,);});after(()=>{app.server.close();});describe('/discriminator_implied',()=>{it('should return 200 for dog',async()=>request(app).post(`${app.basePath}/discriminator_implied`).set('content-type','application/json').send({pet_type: 'DogObject',bark: true,breed: 'Dingo',}).expect(200));it('should return 400 for dog with cat props',async()=>request(app).post(`${app.basePath}/discriminator_implied`).set('content-type','application/json').send({pet_type: 'DogObject',hunts: true,age: 3,}).expect(400).then((r)=>{expect(r.body.message).to.include("required property 'bark'");}));it('should return 400 a bad discriminator',async()=>request(app).post(`${app.basePath}/discriminator_implied`).set('content-type','application/json').send({pet_type: 'dog',bark: true,breed: 'Dingo',}).expect(400).then((r)=>{expect(r.body.message).to.include('one of the allowed values: CatObject, DogObject',);}));});describe('/pets',()=>{it('should return 400 a bad discriminator',async()=>request(app).post(`${app.basePath}/pets`).set('content-type','application/json').send({pet_type: 'DogObject',bark: true,breed: 'Dingo',}).expect(400).then((r)=>{conste=r.body;expect(e.message).to.include('one of the allowed values: cat, dog');}));it('should return 200 for dog',async()=>request(app).post(`${app.basePath}/pets`).set('content-type','application/json').send({pet_type: 'dog',bark: true,breed: 'Dingo',}).expect(200));it('should return 200 for puppy',async()=>request(app).post(`${app.basePath}/pets`).set('content-type','application/json').send({pet_type: 'puppy',bark: true,breed: 'Dingo',}).expect(200));it('should return 200 for cat',async()=>request(app).post(`${app.basePath}/pets`).set('content-type','application/json').send({pet_type: 'cat',hunts: true,age: 1,}).expect(200));it('should return 200 for kitty',async()=>request(app).post(`${app.basePath}/pets`).set('content-type','application/json').send({pet_type: 'kitty',hunts: true,age: 1,}).expect(200));});describe('/pets_all',()=>{it('should return 400 a bad discriminator',async()=>request(app).post(`${app.basePath}/pets_all`).set('content-type','application/json').send({pet_type: 'dog',bark: true,breed: 'Dingo',}).expect(400).then((r)=>{conste=r.body;expect(e.message).to.include('to one of the allowed values: Cat, Dog',);}));it('should return 200 for Dog',async()=>request(app).post(`${app.basePath}/pets_all`).set('content-type','application/json').send({pet_type: 'Dog',bark: true,breed: 'Dingo',}).expect(200));it('should return 200 for Cat',async()=>request(app).post(`${app.basePath}/pets_all`).set('content-type','application/json').send({pet_type: 'Cat',hunts: true,age: 3,}).expect(200));});});
Thank you!
The text was updated successfully, but these errors were encountered:
I've extended one.of.2 test for this case:
Thank you!
The text was updated successfully, but these errors were encountered: