Skip to content
Merged
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
Expand Up @@ -78,7 +78,9 @@
},
"profile": {
"type": "array",
"items": "string"
"items": {
"type": "string"
}
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
"oneOf": [
{
"type": "array",
"items": "string"
"items": {
"type": "string"
}
},
{
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import static com.apicatalog.jsonld.JsonLd.compact;
import static com.apicatalog.jsonld.JsonLd.expand;
import static com.networknt.schema.SpecVersion.VersionFlag.V202012;
import static com.networknt.schema.SpecVersion.VersionFlag.V201909;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.dsp.DspConstants.DSP_CONTEXT;
Expand All @@ -61,7 +61,7 @@ protected void verifyRoundTrip(String jsonFile, String schemaFile) {
var expanded = expand(JsonDocument.of(message)).options(options).get();
var compacted = compact(JsonDocument.of(expanded), JsonDocument.of(compactionContext)).options(options).get();

var schemaFactory = JsonSchemaFactory.getInstance(V202012, builder ->
var schemaFactory = JsonSchemaFactory.getInstance(V201909, builder ->
builder.schemaMappers(schemaMappers -> schemaMappers.mapPrefix(DSP_PREFIX, CLASSPATH_SCHEMA))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void verifyInvalidCases() throws IOException {
assertThat(schema.validate(INVALID_AUTH_MISSING_PROTOCOL, JSON).iterator().next().getType()).isEqualTo(REQUIRED);
assertThat(schema.validate(INVALID_AUTH_PROFILE_NOT_AN_ARRAY, JSON).iterator().next().getType()).isEqualTo(TYPE);
assertThat(schema.validate(INVALID_SERVICEID_NOT_A_STRING, JSON).iterator().next().getType()).isEqualTo(TYPE);
assertThat(schema.validate(INVALID_AUTH_PROFILE_NOT_A_STRING, JSON).iterator().next().getType()).isEqualTo(TYPE);
}

@BeforeEach
Expand Down Expand Up @@ -160,14 +161,32 @@ void setUp() {
"version": "1.0",
"path": "/some/path/v1",
"binding": "HTTPS",
"auth": [{
"auth": {
"protocol": "some-protocol",
"version": "2",
"profile": "one-profile"
}],
"profile": ["one-profile"]
},
"serviceId": 666
}
]
}
""";

private static final String INVALID_AUTH_PROFILE_NOT_A_STRING = """
{
"protocolVersions": [
{
"version": "1.0",
"path": "/some/path/v1",
"binding": "HTTPS",
"auth": {
"protocol": "some-protocol",
"version": "2",
"profile": [666]
},
"serviceId": "some-uuid"
}
]
}
""";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@
*
* Contributors:
* Metaform Systems, Inc. - initial API and implementation
* SAP SE - fixes
*
*/

package org.eclipse.dsp.schema.fixtures;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SchemaLocation;
import com.networknt.schema.SpecVersion;
import com.networknt.schema.ValidationMessage;

import static com.networknt.schema.SpecVersion.VersionFlag.V202012;
import java.io.File;
import java.io.IOException;

import static com.networknt.schema.SchemaId.V201909;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.dsp.DspConstants.DSP_PREFIX;

/**
Expand All @@ -35,15 +42,29 @@ public abstract class AbstractSchemaTest {
protected static final String ENUM = "enum";

private static final String CLASSPATH_SCHEMA = "classpath:/";
private static final String MAIN_RESOURCES = "src/main/resources";


protected ObjectMapper mapper = new ObjectMapper();
protected JsonSchema schema;
protected JsonSchema metaSchema;

protected void setUp(String schemaFile) {
var schemaFactory = JsonSchemaFactory.getInstance(V202012, builder ->
var schemaFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909, builder ->
builder.schemaMappers(schemaMappers -> schemaMappers.mapPrefix(DSP_PREFIX, CLASSPATH_SCHEMA))
);

metaSchema = schemaFactory.getSchema(SchemaLocation.of(V201909));

JsonNode schemaAsNode;
try {
schemaAsNode = mapper.readTree(new File(MAIN_RESOURCES + schemaFile));
} catch (IOException e) {
throw new RuntimeException();
}

assertThat(metaSchema.validate(schemaAsNode)).isEmpty();

schema = schemaFactory.getSchema(SchemaLocation.of(DSP_PREFIX + schemaFile));
}

Expand Down
Loading