Skip to content

Commit

Permalink
fix and exposed id$
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Oct 24, 2024
1 parent 591301c commit b66a584
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/swagger/petstore/model/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Schema(
description = "Category",
$id = "/components/schemas/category"
$id = "/api/v31/components/schemas/category"
)
@XmlRootElement(name = "Category")
public class Category {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/swagger/petstore/model/Pet.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void setStatus(final String status) {
this.status = status;
}

@Schema(name = "petDetails", ref = "/components/schemas/petdetails")
@Schema(name = "petDetails", ref = "/api/v31/components/schemas/petdetails")
public PetDetails getPetDetails() {
return petDetails;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ public void setAvailableInstances(final int availableInstances) {
}

@XmlElement(name = "petDetailsId")
@Schema(name = "petDetailsId", ref = "/components/schemas/petdetails#pet_details_id")
@Schema(name = "petDetailsId", ref = "/api/v31/components/schemas/petdetails#pet_details_id")
public long getPetDetailsId() {
return petDetailsId;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/swagger/petstore/model/PetDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Schema(
$schema = "https://json-schema.org/draft/2020-12/schema",
$vocabulary = "https://spec.openapis.org/oas/3.1/schema-base",
$id = "/components/schemas/petdetails",
$id = "/api/v31/components/schemas/petdetails",
type = "object"
)
public class PetDetails {
Expand All @@ -32,7 +32,7 @@ public void setId(final Long id) {
this.id = id;
}

@Schema(description = "PetDetails Category", ref = "/components/schemas/category")
@Schema(description = "PetDetails Category", ref = "/api/v31/components/schemas/category")
public Category getCategory() {
return category;
}
Expand All @@ -41,7 +41,7 @@ public void setCategory(final Category category) {
this.category = category;
}

@Schema(ref = "/components/schemas/tag")
@Schema(ref = "/api/v31/components/schemas/tag")
public Tag getTag() {
return tag;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/swagger/petstore/model/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import javax.xml.bind.annotation.XmlRootElement;

@Schema(
$id = "/components/schemas/tag"
$id = "/api/v31/components/schemas/tag"
)
@XmlRootElement(name = "Tag")
public class Tag {
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/io/swagger/petstore/resource/CategoryResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.swagger.petstore.resource;

import io.swagger.petstore.data.PetData;
import io.swagger.v3.oas.annotations.Hidden;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/components/schemas/category")
@Produces({"application/json"})
public class CategoryResource {
static PetData petData = new PetData();

@GET
@Hidden
public Response category() {
String json = "{\n" +
" \"Category\" : {\n" +
" \"$id\" : \"/api/v31/components/schemas/category\",\n" +
" \"description\" : \"Category\",\n" +
" \"properties\" : {\n" +
" \"id\" : {\n" +
" \"type\" : \"integer\",\n" +
" \"format\" : \"int64\",\n" +
" \"example\" : 1\n" +
" },\n" +
" \"name\" : {\n" +
" \"type\" : \"string\",\n" +
" \"example\" : \"Dogs\"\n" +
" }\n" +
" },\n" +
" \"xml\" : {\n" +
" \"name\" : \"Category\"\n" +
" }\n" +
" }\n" +
"}";

return Response.ok(json, MediaType.APPLICATION_JSON).build();
}
}
46 changes: 46 additions & 0 deletions src/main/java/io/swagger/petstore/resource/PetDetailsResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.swagger.petstore.resource;

import io.swagger.petstore.data.PetData;
import io.swagger.v3.oas.annotations.Hidden;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/components/schemas/petdetails")
@Produces({"application/json"})
public class PetDetailsResource {
static PetData petData = new PetData();

@GET
@Hidden
public Response petDetails() {
String json = "{\n" +
" \"$id\": \"/api/v31/components/schemas/petdetails\",\n" +
" \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n" +
" \"$vocabulary\": \"https://spec.openapis.org/oas/3.1/schema-base\",\n" +
" \"properties\": {\n" +
" \"id\": {\n" +
" \"type\": \"integer\",\n" +
" \"format\": \"int64\",\n" +
" \"$anchor\": \"pet_details_id\",\n" +
" \"example\": 10\n" +
" },\n" +
" \"category\": {\n" +
" \"$ref\": \"/api/v31/components/schemas/category\",\n" +
" \"description\": \"PetDetails Category\"\n" +
" },\n" +
" \"tag\": {\n" +
" \"$ref\": \"/api/v31/components/schemas/tag\"\n" +
" }\n" +
" },\n" +
" \"xml\": {\n" +
" \"name\": \"PetDetails\"\n" +
" }\n" +
"}";

return Response.ok(json, MediaType.APPLICATION_JSON).build();
}
}
38 changes: 38 additions & 0 deletions src/main/java/io/swagger/petstore/resource/TagResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.swagger.petstore.resource;

import io.swagger.petstore.data.PetData;
import io.swagger.v3.oas.annotations.Hidden;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/components/schemas/tag")
@Produces({"application/json"})
public class TagResource {
static PetData petData = new PetData();

@GET
@Hidden
public Response tag() {
String json = "{\n" +
" \"$id\": \"/api/v3/components/schemas/tag\",\n" +
" \"properties\": {\n" +
" \"id\": {\n" +
" \"type\": \"integer\",\n" +
" \"format\": \"int64\"\n" +
" },\n" +
" \"name\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" },\n" +
" \"xml\": {\n" +
" \"name\": \"Tag\"\n" +
" }\n" +
"}";

return Response.ok(json, MediaType.APPLICATION_JSON).build();
}
}
14 changes: 7 additions & 7 deletions src/main/webapp/code-first/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
"components" : {
"schemas" : {
"Category" : {
"$id" : "/components/schemas/category",
"$id" : "/api/v31/components/schemas/category",
"description" : "Category",
"properties" : {
"id" : {
Expand Down Expand Up @@ -285,10 +285,10 @@
"petDetailsId" : {
"type" : "integer",
"format" : "int64",
"$ref" : "/components/schemas/petdetails#pet_details_id"
"$ref" : "/api/v31/components/schemas/petdetails#pet_details_id"
},
"petDetails" : {
"$ref" : "/components/schemas/petdetails"
"$ref" : "/api/v31/components/schemas/petdetails"
}
},
"required" : [ "name", "photoUrls" ],
Expand All @@ -297,7 +297,7 @@
}
},
"PetDetails" : {
"$id" : "/components/schemas/petdetails",
"$id" : "/api/v31/components/schemas/petdetails",
"$schema" : "https://json-schema.org/draft/2020-12/schema",
"$vocabulary" : "https://spec.openapis.org/oas/3.1/schema-base",
"properties" : {
Expand All @@ -308,19 +308,19 @@
"example" : 10
},
"category" : {
"$ref" : "/components/schemas/category",
"$ref" : "/api/v31/components/schemas/category",
"description" : "PetDetails Category"
},
"tag" : {
"$ref" : "/components/schemas/tag"
"$ref" : "/api/v31/components/schemas/tag"
}
},
"xml" : {
"name" : "PetDetails"
}
},
"Tag" : {
"$id" : "/components/schemas/tag",
"$id" : "/api/v31/components/schemas/tag",
"properties" : {
"id" : {
"type" : "integer",
Expand Down
14 changes: 7 additions & 7 deletions src/main/webapp/code-first/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ paths:
components:
schemas:
Category:
$id: /components/schemas/category
$id: /api/v31/components/schemas/category
description: Category
properties:
id:
Expand Down Expand Up @@ -226,16 +226,16 @@ components:
petDetailsId:
type: integer
format: int64
$ref: /components/schemas/petdetails#pet_details_id
$ref: /api/v31/components/schemas/petdetails#pet_details_id
petDetails:
$ref: /components/schemas/petdetails
$ref: /api/v31/components/schemas/petdetails
required:
- name
- photoUrls
xml:
name: Pet
PetDetails:
$id: /components/schemas/petdetails
$id: /api/v31/components/schemas/petdetails
$schema: https://json-schema.org/draft/2020-12/schema
$vocabulary: https://spec.openapis.org/oas/3.1/schema-base
properties:
Expand All @@ -245,14 +245,14 @@ components:
$anchor: pet_details_id
example: 10
category:
$ref: /components/schemas/category
$ref: /api/v31/components/schemas/category
description: PetDetails Category
tag:
$ref: /components/schemas/tag
$ref: /api/v31/components/schemas/tag
xml:
name: PetDetails
Tag:
$id: /components/schemas/tag
$id: /api/v31/components/schemas/tag
properties:
id:
type: integer
Expand Down

0 comments on commit b66a584

Please sign in to comment.