Skip to content

Commit

Permalink
fix: keep unrelated updated content section with one-of transformer (#27
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mohnoor94 authored Jul 12, 2023
1 parent 5e44d70 commit 8e6999a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expediagroup/spec-transformer",
"version": "1.4.0",
"version": "1.5.0",
"description": "API Spec Transformer",
"repository": {
"type": "git",
Expand Down
14 changes: 8 additions & 6 deletions src/model/Spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ export default class Spec {

const mappings = this.getComponentMappings();

const setOperationFieldValue = (operationField: Key, operationFieldValue: Value) => {
const setOperationFieldValue = (operationFields: Value, operationField: Key, operationFieldValue: Value) => {
if (operationField === REQUEST_BODY) {
return this.buildOneOfRequest(operationFieldValue, mappings);
return this.buildOneOfRequest(operationFields, operationFieldValue, mappings);
}

if (operationField === RESPONSES) {
return this.buildOneOfResponse(operationFieldValue, mappings);
return this.buildOneOfResponse(operationFields, operationFieldValue, mappings);
}

return operationFieldValue;
Expand All @@ -144,7 +144,7 @@ export default class Spec {
map(operationFields, (operationField, operationFieldValue) => {
return [
operationField,
setOperationFieldValue(operationField, operationFieldValue)
setOperationFieldValue(operationFields, operationField, operationFieldValue)
];
})
])
Expand All @@ -165,7 +165,7 @@ export default class Spec {
});
};

private buildOneOfRequest(operationFieldValue: Value, mappings: Record<Key, Value>): Record<Key, Value> {
private buildOneOfRequest(operationFields: Value, operationFieldValue: Value, mappings: Record<Key, Value>): Record<Key, Value> {
const isDirectRef = this.isRef(operationFieldValue);
const schemaValue = isDirectRef ? operationFieldValue : operationFieldValue.content['application/json'].schema;

Expand All @@ -181,6 +181,7 @@ export default class Spec {
content: {
...operationFieldValue.content,
'application/json': {
...operationFields.requestBody.content['application/json'],
schema: {
oneOf: this.buildOneOfList(mappings.get(name))
}
Expand All @@ -189,7 +190,7 @@ export default class Spec {
};
}

private buildOneOfResponse(operationFieldValue: Value, mappings: Record<Key, Value>): Record<Key, Value> {
private buildOneOfResponse(operationFields: Value, operationFieldValue: Value, mappings: Record<Key, Value>): Record<Key, Value> {
return map(operationFieldValue, (response, responseFields) => {
const isDirectRef = this.isRef(responseFields);

Expand All @@ -210,6 +211,7 @@ export default class Spec {
content: {
...responseFields.content,
'application/json': {
...responseFields.content['application/json'],
schema: {
oneOf: this.buildOneOfList(mappings.get(name))
}
Expand Down

0 comments on commit 8e6999a

Please sign in to comment.