Skip to content

Commit

Permalink
refs #3311 - tests DELETE ME
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Oct 1, 2019
1 parent 01fa303 commit 4a965d6
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
*/
Schema resolvedModel = context.resolve(annotatedType);
if (resolvedModel != null) {
if (name.equals(resolvedModel.getName())) {
if (name != null && name.equals(resolvedModel.getName())) {
return resolvedModel;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package io.swagger.v3.core.resolving;

import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.core.converter.ModelConverterContextImpl;
import io.swagger.v3.core.jackson.ModelResolver;
import io.swagger.v3.core.matchers.SerializationMatchers;
import io.swagger.v3.core.resolving.resources.HalBean;
import io.swagger.v3.core.resolving.resources.TestObject2992;
import io.swagger.v3.core.util.PrimitiveType;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.Test;

public class Ticket3311Test extends SwaggerTestBase {

@Test
public void testLocalTime() throws Exception {

final ModelResolver modelResolver = new ModelResolver(mapper());

ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);

Schema model = context
.resolve(new AnnotatedType(HalBean.class));

SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "LocalTime:\n" +
" type: object\n" +
" properties:\n" +
" hour:\n" +
" type: integer\n" +
" format: int32\n" +
" minute:\n" +
" type: integer\n" +
" format: int32\n" +
" second:\n" +
" type: integer\n" +
" format: int32\n" +
" nano:\n" +
" type: integer\n" +
" format: int32\n" +
"TestObject2992:\n" +
" type: object\n" +
" properties:\n" +
" name:\n" +
" type: string\n" +
" a:\n" +
" $ref: '#/components/schemas/LocalTime'\n" +
" b:\n" +
" $ref: '#/components/schemas/LocalTime'\n" +
" c:\n" +
" $ref: '#/components/schemas/LocalTime'\n" +
" d:\n" +
" type: string\n" +
" format: date-time\n" +
" e:\n" +
" type: string\n" +
" format: date-time\n" +
" f:\n" +
" type: string\n" +
" format: date-time");

PrimitiveType.enablePartialTime();
context = new ModelConverterContextImpl(modelResolver);

context
.resolve(new AnnotatedType(TestObject2992.class));

SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "TestObject2992:\n" +
" type: object\n" +
" properties:\n" +
" name:\n" +
" type: string\n" +
" a:\n" +
" type: string\n" +
" format: partial-time\n" +
" b:\n" +
" type: string\n" +
" format: partial-time\n" +
" c:\n" +
" type: string\n" +
" format: partial-time\n" +
" d:\n" +
" type: string\n" +
" format: date-time\n" +
" e:\n" +
" type: string\n" +
" format: date-time\n" +
" f:\n" +
" type: string\n" +
" format: date-time");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.swagger.v3.core.resolving.resources;

//import mypackage.bean.ImmutableStyle;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.v3.core.oas.models.Cat;
//import io.swagger.annotations.ApiModel;
import java.util.List;
import java.util.Map;
import java.util.Optional;
//import org.immutables.value.Value;

/**
* The HateoasBean contains another Jackson-serializable bean plus links to other resources.
*
* It's done like this to not pollute all the JSON beans with _links entries.
*/
//@ApiModel(value = "HALBean", description = "Root bean of all return values")
//@Value.Immutable
//@ImmutableStyle
//@JsonSerialize(as = ImmutableHalBean.class)
//@JsonDeserialize(as = ImmutableHalBean.class)
public interface HalBean { //<T> {

//@JsonProperty("_embedded")
//Map<String, List<HalBean<T>>> getEmbedded();
//List<HalBean<T>> getEmbedded();
HalBean getEmbedded();
//Object getEmbedded();

@JsonUnwrapped
Optional<Foo> getBean();
//Optional<T> getBean();


//@JsonProperty("_links")
//Optional<Links> getLinks();


/*
static <T> HalBean<T> of(final T bean, final Links links) {
return null;
//return ImmutableHalBean.<T>builder().setBean(bean).setLinks(links).build();
}
static <T> HalBean<T> of(final Links links) {
return null;
//return ImmutableHalBean.<T>builder().setLinks(links).build();
}
*/

public static class Foo{
public String bar;
}
}

0 comments on commit 4a965d6

Please sign in to comment.