Skip to content

Commit

Permalink
Revert "fix polymoprhic with nullable patching (#2636)"
Browse files Browse the repository at this point in the history
This reverts commit 2849178.
  • Loading branch information
niclim committed Jan 2, 2024
1 parent 39bf290 commit 601b761
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -751,57 +751,6 @@ exports[`generateEndpointSpecPatches OAS version 3.0.1 allOf with nested oneOf 2
}
`;

exports[`generateEndpointSpecPatches OAS version 3.0.1 allOf with nullable 1`] = `[]`;

exports[`generateEndpointSpecPatches OAS version 3.0.1 allOf with nullable 2`] = `
{
"info": {},
"openapi": "3.0.1",
"paths": {
"/api/animals": {
"post": {
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"properties": {
"key": {
"allOf": [
{
"properties": {
"goodbye": {
"type": "string",
},
"hello": {
"type": "string",
},
},
"required": [
"hello",
"goodbye",
],
"type": "object",
},
],
"nullable": true,
},
},
"required": [
"key",
],
"type": "object",
},
},
},
},
},
},
},
},
}
`;

exports[`generateEndpointSpecPatches OAS version 3.0.1 array with multiple items 1`] = `
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,65 +980,6 @@ describe('generateEndpointSpecPatches', () => {
expect(patches).toMatchSnapshot();
expect(specHolder.spec).toMatchSnapshot();
});

test('with nullable', async () => {
// nullable keyword only valid in 3.0.1
if (version !== '3.0.1') return;
specHolder.spec.paths['/api/animals'].post.responses = {
'200': {
content: {
'application/json': {
schema: {
type: 'object',
required: ['key'],
properties: {
key: {
nullable: true,
allOf: [
{
type: 'object',
properties: {
hello: {
type: 'string',
},
goodbye: {
type: 'string',
},
},
required: ['hello', 'goodbye'],
},
],
},
},
},
},
},
},
};

const interaction = makeInteraction(
{ method: OpenAPIV3.HttpMethods.POST, path: '/api/animals' },
{
responseBody: {
key: null,
},
}
);

const patches = await AT.collect(
generateEndpointSpecPatches(
GenerateInteractions([interaction]),
specHolder,
{
method: 'post',
path: '/api/animals',
}
)
);

expect(patches).toMatchSnapshot();
expect(specHolder.spec).toMatchSnapshot();
});
});

describe.each([['query'], ['header']])('%s parameter', (location) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,10 @@ function prepareSchemaForDiff(input: SchemaObject): SchemaObject {

// Fix case where nullable is set and there is no type key
if (!schema.type && schema.nullable) {
// if polymorphic, this could also be nullable
if (!(schema.oneOf || schema.anyOf || schema.allOf)) {
if (schema.oneOf || schema.anyOf || schema.allOf) {
// in the polymorphic case we have to remove nullable, since type will override and you cannot use
delete schema.nullable;
} else {
// We set this to string since we're not sure what the actual type is; this should be fine for us since we'll use this schema for diffing purposes and update
schema.type = 'string';
}
Expand Down

0 comments on commit 601b761

Please sign in to comment.