-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
readOnly does not work together with polymorphic oneOf. #400
Comments
The problem is in this code. As is, it does not handle anyOf, allOf, oneOf. The following new test e.g. import * as path from 'path';
import * as express from 'express';
import * as request from 'supertest';
import { createApp } from './common/app';
describe.only('one.of readonly', () => {
let app = null;
before(async () => {
// Set up the express app
const apiSpec = path.join(__dirname, 'oneof.readonly.yaml');
app = await createApp({ apiSpec }, 3005, (app) =>
app.use(
express
.Router()
.post(`${app.basePath}/orders`, (req, res) =>
res.status(200).json({ success: true }),
),
),
);
});
after(() => {
app.server.close();
});
it('post type (without readonly id) should pass', async () =>
request(app)
.post(`${app.basePath}/orders`)
.send({ type: 'A' })
.set('Content-Type', 'application/json')
.expect(200))
}); |
@hallsbyra please give |
Thanks, seems to be almost solved. My original spec still doesn't work though, but that seems to be related to #104. And is easily fixed by getting rid of the openapi: 3.0.0
info:
title: Dummy API
description: Dummy API
version: "0.1.0"
servers:
- url: /v1
paths:
"/orders":
post:
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: "#/components/schemas/subA"
- $ref: "#/components/schemas/subB"
responses:
200:
description: successful operation
components:
schemas:
common:
type: object
properties:
id:
readOnly: true
type: string
required:
- id
subA:
allOf:
- $ref: "#/components/schemas/common"
properties:
type:
type: string
enum: [A]
required:
- type
subB:
allOf:
- $ref: "#/components/schemas/common"
properties:
type:
type: string
enum: [B]
required:
- type Problem is just that the above spec gives It took a glance in the code yesterday and saw that you're removing |
yep, good catch. if there is only one required field and its readonly we need to remove the required field itself |
* remove required if no required props exist * (fix) #400 readonly with single required prop fails * remove 15
@hallsbyra this issue is fixed in |
* remove required if no required props exist * (fix) cdimascio#400 readonly with single required prop fails * remove 15
Describe the bug
readOnly
does not work together with polymorphiconeOf
.To Reproduce
Use this spec:
POST this request to /v1/orders:
Actual behavior
Validation errors:
Expected behavior
Request should be accepted, since
id
isreadOnly
.The text was updated successfully, but these errors were encountered: