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

Test and fix #2083 properties in ComposedModel #2084

Merged
merged 1 commit into from
May 2, 2024
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 @@ -37,13 +37,13 @@ public void processModel(Model model) {
} else if (model instanceof ComposedModel) {
processComposedModel((ComposedModel) model);
} else if (model instanceof ModelImpl) {
processModelImpl((ModelImpl) model);
processModelProperties( model);
}
}

private void processModelImpl(ModelImpl modelImpl) {
private void processModelProperties(Model model) {

final Map<String, Property> properties = modelImpl.getProperties();
final Map<String, Property> properties = model.getProperties();

if (properties == null) {
return;
Expand All @@ -68,6 +68,7 @@ private void processComposedModel(ComposedModel composedModel) {
}
}

processModelProperties(composedModel);
}

private void processArrayModel(ArrayModel arrayModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.models.*;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.RefProperty;
import io.swagger.models.refs.RefFormat;
import io.swagger.parser.ResolverCache;
import mockit.*;
Expand Down Expand Up @@ -150,4 +151,56 @@ private void setupPropertyAndExternalRefProcessors() {
result = externalRefProcessor;
}};
}


@Test
public void testProcessComposedModelWithProperties(@Injectable final Property property1) throws Exception {
setupPropertyAndExternalRefProcessors();

final String ref1 = "http://my.company.com/path/to/file.json#/foo/bar";
final String ref2 = "http://my.company.com/path/to/file.json#/this/that";
final String ref3 = "http://my.company.com/path/to/file.json#/hello/world";
final String ref4 = "http://my.company.com/path/to/file.json#/hello/ref";
final Property property2 = new RefProperty(ref4);

ModelProcessor modelProcessor = new ModelProcessor(cache, swagger);

new Expectations() {{
externalRefProcessor.processRefToExternalDefinition(ref1, RefFormat.URL);
times = 1;
result = "bar";
externalRefProcessor.processRefToExternalDefinition(ref2, RefFormat.URL);
times = 1;
result = "that";
externalRefProcessor.processRefToExternalDefinition(ref3, RefFormat.URL);
times = 1;
result = "world";
propertyProcessor.processProperty(property1);
times = 1;
propertyProcessor.processProperty(property2);
times = 1;
}};

ComposedModel composedModel = new ComposedModel();
composedModel.child(new RefModel(ref1));
composedModel.parent(new RefModel(ref2));
composedModel.interfaces(Arrays.asList(new RefModel(ref3)));
composedModel.addProperty("foo", property1);
composedModel.addProperty("bar", property2);

modelProcessor.processModel(composedModel);

new FullVerifications() {{
externalRefProcessor.processRefToExternalDefinition(ref1, RefFormat.URL);
times = 1;
externalRefProcessor.processRefToExternalDefinition(ref2, RefFormat.URL);
times = 1;
externalRefProcessor.processRefToExternalDefinition(ref3, RefFormat.URL);
times = 1;
}};

assertEquals(((RefModel) composedModel.getChild()).get$ref(), "#/definitions/bar");
assertEquals(((RefModel) composedModel.getParent()).get$ref(), "#/definitions/that");
assertEquals((composedModel.getInterfaces().get(0)).get$ref(), "#/definitions/world");
}
}
Loading