Skip to content

Commit

Permalink
making the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RoshniNaveenaS committed Sep 10, 2024
1 parent 93f3015 commit e473871
Show file tree
Hide file tree
Showing 4 changed files with 3,772 additions and 3,573 deletions.
38 changes: 26 additions & 12 deletions lib/compile/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1638,19 +1638,33 @@ see [Expand](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-prot
if (code != 204) {
const s = getSchema(type);
r[code].content = {
'application/json': {
schema: type.$Collection
? {
type: 'object',
title: 'Collection of ' + nameParts(type.$Type || 'Edm.String').name,
properties: {
...(isCount && CountPropertyObj),
value: s
}
}
: s
}
'application/json': {}
};

if (type.$Collection) {
r[code].content['application/json'].schema = {
type: 'object',
title: 'Collection of ' + nameParts(type.$Type ? type.$Type : 'Edm.String').name,
properties: {
...(isCount && CountPropertyObj),
value: s
}
};
}

else if (
type.$Type === undefined ||
(type.$Type.startsWith("Edm.") &&
!["Edm.Stream", "Edm.EntityType", "Edm.ComplexType"].includes(
type.$Type,
))
) {
r[code].content['application/json'].schema = { type: "object", properties: { value: s } };
}

else {
r[code].content['application/json'].schema = s;
}
}
if (errors) {
for (const e of errors) {
Expand Down
158 changes: 114 additions & 44 deletions test/lib/compile/csdl2openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,53 +856,123 @@ describe('Edge cases', function () {
const expected = {
paths: {
'/fun()': {
get: {
responses: {
200: {
description: 'Success',
content: {
'application/json': {
schema: {
type: 'string',
maxLength: 20
}
}
}
}
}
"paths": {
"/$batch": {
"post": {
"summary": "Sends a group of requests",
"description": "Group multiple requests into a single request payload, see [Batch Requests](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_BatchRequests).\n\n*Please note that \"Try it out\" is not supported for this request.*",
"tags": [
"Batch Requests"
],
"requestBody": {
"required": true,
"description": "Batch request",
"content": {
"multipart/mixed;boundary=request-separator": {
"schema": {
"type": "string"
},
"example": "--request-separator\nContent-Type: application/http\nContent-Transfer-Encoding: binary\n\nGET undefined HTTP/1.1\nAccept: application/json\n\n\n--request-separator--"
}
}
},
"responses": {
"200": {
"description": "Batch response",
"content": {
"multipart/mixed": {
"schema": {
"type": "string"
},
"example": "--response-separator\nContent-Type: application/http\n\nHTTP/1.1 200 OK\nContent-Type: application/json\n\n{...}\n--response-separator--"
}
}
},
"4XX": {
"$ref": "#/components/responses/error"
}
}
}
},
"/fun()": {
"get": {
"summary": "Invokes function fun",
"tags": [
"Service Operations"
],
"parameters": [],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"value": {
"type": "string",
"maxLength": 20
}
},
"/fun(in={in})": {
get: {
responses: {
200: {
description: 'Success',
content: {
'application/json': {
schema: {
type: 'object',
title: 'Collection of String',
properties: {
'@odata.count': {
$ref: '#/components/schemas/count'
},
value: {
type: 'array',
items: {
type: 'string',
maxLength: 20
}
}
}
}
}
}
}
}
}
}
}
}
},
"4XX": {
"$ref": "#/components/responses/error"
}
}
}
},
"/fun(in={in})": {
"get": {
"summary": "Invokes function fun",
"tags": [
"Service Operations"
],
"parameters": [
{
"required": true,
"in": "path",
"name": "in",
"description": "String value needs to be enclosed in single quotes",
"schema": {
"type": "string",
"pattern": "^'([^']|'')*'$"
}
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"type": "object",
"title": "Collection of String",
"properties": {
"@odata.count": {
"$ref": "#/components/schemas/count"
},
"value": {
"type": "array",
"items": {
"type": "string",
"maxLength": 20
}
}
},
'/$batch': { post: {} }
}
}
}
}
},
"4XX": {
"$ref": "#/components/responses/error"
}
}
}
}
}
};
const actual = lib.csdl2openapi(csdl, {odataVersion: '4.0'});
assert.deepStrictEqual(paths(actual), paths(expected), 'Paths');
Expand Down
99 changes: 72 additions & 27 deletions test/lib/compile/data/containment.openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -2567,9 +2567,14 @@
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
}
}
}
}
}
Expand Down Expand Up @@ -2614,9 +2619,14 @@
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
}
}
}
}
}
Expand Down Expand Up @@ -3080,9 +3090,14 @@
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
}
}
}
}
}
Expand Down Expand Up @@ -3127,9 +3142,14 @@
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
}
}
}
}
}
Expand Down Expand Up @@ -4351,9 +4371,14 @@
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
}
}
}
}
}
Expand Down Expand Up @@ -4419,9 +4444,14 @@
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
}
}
}
}
}
Expand Down Expand Up @@ -4948,9 +4978,14 @@
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
}
}
}
}
}
Expand Down Expand Up @@ -5016,9 +5051,14 @@
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
}
}
}
}
}
Expand Down Expand Up @@ -5063,9 +5103,14 @@
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
"type": "object",
"properties": {
"value": {
"type": "integer",
"format": "int32",
"nullable": true
}
}
}
}
}
Expand Down
Loading

0 comments on commit e473871

Please sign in to comment.