Skip to content
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

Converting yes no on off enum values without quotes to booleans problem #1709

Open
wants to merge 4 commits into
base: v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.swagger.parser.util;

import com.fasterxml.jackson.databind.JsonNode;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotSame;

public class DeserializationUtilsTest {

@Test
public void testEnumValuesAreNotConvertedToBooleansOAS2() throws IOException {
String yaml = readFile("src/test/resources/EnumYesNoOnOffOAS2.yaml");

JsonNode jsonNode = DeserializationUtils.readYamlTree(yaml, null);

jsonNode.findPath("EnumWithQuotes").get("enum").elements()
.forEachRemaining(element -> {
assertFalse(element.isBoolean());
assertNotSame(element.textValue(), "true");
assertNotSame(element.textValue(), "false");
});
jsonNode.findPath("EnumNoQuotes").get("enum").elements()
.forEachRemaining(element -> {
assertFalse(element.isBoolean());
assertNotSame(element.textValue(), "true");
assertNotSame(element.textValue(), "false");
});
}

@Test
public void testEnumValuesAreNotConvertedToBooleansOAS3() throws IOException {
String yaml = readFile("src/test/resources/EnumYesNoOnOffOAS3.yaml");

JsonNode jsonNode = DeserializationUtils.readYamlTree(yaml, null);

jsonNode.findPath("EnumWithQuotes").get("enum").elements()
.forEachRemaining(element -> {
assertFalse(element.isBoolean());
assertNotSame(element.textValue(), "true");
assertNotSame(element.textValue(), "false");
});
jsonNode.findPath("EnumNoQuotes").get("enum").elements()
.forEachRemaining(element -> {
assertFalse(element.isBoolean());
assertNotSame(element.textValue(), "true");
assertNotSame(element.textValue(), "false");
});
}


private String readFile(String name) throws IOException {
return new String(Files.readAllBytes(new File(name).toPath()), StandardCharsets.UTF_8);
}
}
46 changes: 46 additions & 0 deletions modules/swagger-parser/src/test/resources/EnumYesNoOnOffOAS2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
swagger: '2.0'
info:
title: Yes No On Off string test
version: 1.0.0
paths: {}
definitions:
EnumNoQuotes:
type: string
enum:
- some_string
- y
- Y
- yes
- Yes
- YES
- n
- N
- no
- No
- NO
- on
- On
- ON
- off
- Off
- OFF
EnumWithQuotes:
type: string
enum:
- some_string
- 'y'
- 'Y'
- 'yes'
- 'Yes'
- 'YES'
- 'n'
- 'N'
- 'no'
- 'No'
- 'NO'
- 'on'
- 'On'
- 'ON'
- 'off'
- 'Off'
- 'OFF'
47 changes: 47 additions & 0 deletions modules/swagger-parser/src/test/resources/EnumYesNoOnOffOAS3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
openapi: 3.0.0
info:
title: Yes No On Off string test
version: 1.0.0
paths: {}
components:
schemas:
EnumNoQuotes:
type: string
enum:
- some_string
- y
- Y
- yes
- Yes
- YES
- n
- N
- no
- No
- NO
- on
- On
- ON
- off
- Off
- OFF
EnumWithQuotes:
type: string
enum:
- some_string
- 'y'
- 'Y'
- 'yes'
- 'Yes'
- 'YES'
- 'n'
- 'N'
- 'no'
- 'No'
- 'NO'
- 'on'
- 'On'
- 'ON'
- 'off'
- 'Off'
- 'OFF'
Loading