Skip to content

Commit f4f9ff7

Browse files
author
bnasslahsen
committed
Wrong @manytoone relationship naming. Fixes #861.
1 parent 2432777 commit f4f9ff7

File tree

3 files changed

+58
-59
lines changed

3 files changed

+58
-59
lines changed

springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/SpringRepositoryRestResourceProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ public List<RouterOperation> getRouterOperations(OpenAPI openAPI) {
173173
entity.doWithAssociations((SimpleAssociationHandler) association -> {
174174
PersistentProperty<?> property = association.getInverse();
175175
if (jackson.isExported(property) && associations.isLinkableAssociation(property)) {
176-
ResourceMetadata targetTypeMetadata = associations.getMetadataFor(property.getActualType());
177-
dataRestRepository.setRelationName(targetTypeMetadata.getItemResourceRel().toString());
176+
dataRestRepository.setRelationName(resourceMetadata.getMappingFor(property).getRel().value());
178177
dataRestRepository.setControllerType(ControllerType.PROPERTY);
179178
findControllers(routerOperationList, handlerMethodMapFilteredMethodMap, resourceMetadata, dataRestRepository, openAPI);
180179
}

springdoc-openapi-data-rest/src/test/java/test/org/springdoc/api/app17/Property.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Property {
2121

2222
@ManyToOne
2323
@JoinColumn(name = "child_property_id")
24-
private ChildProperty childProperty;
24+
private ChildProperty myChildPropertyName;
2525

2626
public long getId() {
2727
return id;
@@ -39,11 +39,11 @@ public void setName(String name) {
3939
this.name = name;
4040
}
4141

42-
public ChildProperty getChildProperty() {
43-
return childProperty;
42+
public ChildProperty getMyChildPropertyName() {
43+
return myChildPropertyName;
4444
}
4545

46-
public void setChildProperty(ChildProperty childProperty) {
47-
this.childProperty = childProperty;
46+
public void setMyChildPropertyName(ChildProperty myChildPropertyName) {
47+
this.myChildPropertyName = myChildPropertyName;
4848
}
4949
}

springdoc-openapi-data-rest/src/test/resources/results/app17.json

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@
583583
}
584584
}
585585
},
586-
"/properties/{id}/childProperty": {
586+
"/properties/{id}/myChildPropertyName": {
587587
"get": {
588588
"tags": [
589589
"property-property-reference-controller"
@@ -759,7 +759,7 @@
759759
}
760760
}
761761
},
762-
"/properties/{id}/childProperty/{propertyId}": {
762+
"/properties/{id}/myChildPropertyName/{propertyId}": {
763763
"get": {
764764
"tags": [
765765
"property-property-reference-controller"
@@ -903,12 +903,6 @@
903903
}
904904
}
905905
},
906-
"Links": {
907-
"type": "object",
908-
"additionalProperties": {
909-
"$ref": "#/components/schemas/Link"
910-
}
911-
},
912906
"RepresentationModelObject": {
913907
"type": "object",
914908
"properties": {
@@ -929,34 +923,22 @@
929923
}
930924
}
931925
},
932-
"CollectionModelChildProperty": {
926+
"Property": {
933927
"type": "object",
934928
"properties": {
935-
"_embedded": {
936-
"type": "object",
937-
"properties": {
938-
"childProperties": {
939-
"type": "array",
940-
"items": {
941-
"$ref": "#/components/schemas/ChildProperty"
942-
}
943-
}
944-
}
929+
"id": {
930+
"type": "integer",
931+
"format": "int64"
945932
},
946-
"_links": {
947-
"$ref": "#/components/schemas/Links"
948-
}
949-
}
950-
},
951-
"RepresentationModelChildProperty": {
952-
"type": "object",
953-
"properties": {
954-
"_links": {
955-
"$ref": "#/components/schemas/Links"
933+
"name": {
934+
"type": "string"
935+
},
936+
"myChildPropertyName": {
937+
"$ref": "#/components/schemas/ChildProperty"
956938
}
957939
}
958940
},
959-
"EntityModelChildProperty": {
941+
"EntityModelProperty": {
960942
"type": "object",
961943
"properties": {
962944
"id": {
@@ -966,6 +948,23 @@
966948
"name": {
967949
"type": "string"
968950
},
951+
"myChildPropertyName": {
952+
"$ref": "#/components/schemas/ChildProperty"
953+
},
954+
"_links": {
955+
"$ref": "#/components/schemas/Links"
956+
}
957+
}
958+
},
959+
"Links": {
960+
"type": "object",
961+
"additionalProperties": {
962+
"$ref": "#/components/schemas/Link"
963+
}
964+
},
965+
"RepresentationModelProperty": {
966+
"type": "object",
967+
"properties": {
969968
"_links": {
970969
"$ref": "#/components/schemas/Links"
971970
}
@@ -990,30 +989,26 @@
990989
}
991990
}
992991
},
993-
"Property": {
992+
"CollectionModelObject": {
994993
"type": "object",
995994
"properties": {
996-
"id": {
997-
"type": "integer",
998-
"format": "int64"
999-
},
1000-
"name": {
1001-
"type": "string"
995+
"_embedded": {
996+
"type": "object",
997+
"properties": {
998+
"objects": {
999+
"type": "array",
1000+
"items": {
1001+
"type": "object"
1002+
}
1003+
}
1004+
}
10021005
},
1003-
"childProperty": {
1004-
"$ref": "#/components/schemas/ChildProperty"
1005-
}
1006-
}
1007-
},
1008-
"RepresentationModelProperty": {
1009-
"type": "object",
1010-
"properties": {
10111006
"_links": {
10121007
"$ref": "#/components/schemas/Links"
10131008
}
10141009
}
10151010
},
1016-
"EntityModelProperty": {
1011+
"EntityModelChildProperty": {
10171012
"type": "object",
10181013
"properties": {
10191014
"id": {
@@ -1023,24 +1018,29 @@
10231018
"name": {
10241019
"type": "string"
10251020
},
1026-
"childProperty": {
1027-
"$ref": "#/components/schemas/ChildProperty"
1028-
},
10291021
"_links": {
10301022
"$ref": "#/components/schemas/Links"
10311023
}
10321024
}
10331025
},
1034-
"CollectionModelObject": {
1026+
"RepresentationModelChildProperty": {
1027+
"type": "object",
1028+
"properties": {
1029+
"_links": {
1030+
"$ref": "#/components/schemas/Links"
1031+
}
1032+
}
1033+
},
1034+
"CollectionModelChildProperty": {
10351035
"type": "object",
10361036
"properties": {
10371037
"_embedded": {
10381038
"type": "object",
10391039
"properties": {
1040-
"objects": {
1040+
"childProperties": {
10411041
"type": "array",
10421042
"items": {
1043-
"type": "object"
1043+
"$ref": "#/components/schemas/ChildProperty"
10441044
}
10451045
}
10461046
}

0 commit comments

Comments
 (0)