-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more documentation for REST interfaces.
- Loading branch information
Showing
13 changed files
with
351 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
= RESTful Notes API Guide | ||
Andy Wilkinson; | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlightjs | ||
:toc: left | ||
:toclevels: 4 | ||
:sectlinks: | ||
:operation-curl-request-title: Example request | ||
:operation-http-response-title: Example response | ||
|
||
[[overview]] | ||
= Overview | ||
|
||
[[overview-http-verbs]] | ||
== HTTP verbs | ||
|
||
RESTful notes tries to adhere as closely as possible to standard HTTP and REST conventions in its | ||
use of HTTP verbs. | ||
|
||
|=== | ||
| Verb | Usage | ||
|
||
| `GET` | ||
| Used to retrieve a resource | ||
|
||
| `POST` | ||
| Used to create a new resource | ||
|
||
| `PATCH` | ||
| Used to update an existing resource, including partial updates | ||
|
||
| `DELETE` | ||
| Used to delete an existing resource | ||
|=== | ||
|
||
[[overview-http-status-codes]] | ||
== HTTP status codes | ||
|
||
RESTful notes tries to adhere as closely as possible to standard HTTP and REST conventions in its | ||
use of HTTP status codes. | ||
|
||
|=== | ||
| Status code | Usage | ||
|
||
| `200 OK` | ||
| The request completed successfully | ||
|
||
| `201 Created` | ||
| A new resource has been created successfully. The resource's URI is available from the response's | ||
`Location` header | ||
|
||
| `204 No Content` | ||
| An update to an existing resource has been applied successfully | ||
|
||
| `400 Bad Request` | ||
| The request was malformed. The response body will include an error providing further information | ||
|
||
| `404 Not Found` | ||
| The requested resource did not exist | ||
|=== | ||
|
||
[[overview-headers]] | ||
== Headers | ||
|
||
Every response has the following header(s): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
fhir/src/test/java/org/dhis2/fhir/adapter/fhir/AbstractJpaRepositoryRestDocsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.dhis2.fhir.adapter.fhir; | ||
|
||
/* | ||
* Copyright (c) 2004-2018, University of Oslo | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the HISP project nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.springframework.restdocs.JUnitRestDocumentation; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; | ||
import org.springframework.test.annotation.Rollback; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; | ||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; | ||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; | ||
|
||
/** | ||
* Abstract test class that generate REST documentation for JPA repositories. | ||
* | ||
* @author volsch | ||
*/ | ||
@Transactional | ||
@Rollback | ||
public abstract class AbstractJpaRepositoryRestDocsTest extends AbstractJpaRepositoryTest | ||
{ | ||
@Rule | ||
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(); | ||
|
||
protected RestDocumentationResultHandler documentationHandler; | ||
|
||
protected MockMvc docMockMvc; | ||
|
||
@Before | ||
public void beforeAbstractJpaRepositoryRestDocsTest() | ||
{ | ||
documentationHandler = document( "{method-name}", | ||
preprocessRequest( prettyPrint() ), | ||
preprocessResponse( removeHeaders( "X-Content-Type-Options", "X-XSS-Protection", "X-Frame-Options" ), prettyPrint() ) ); | ||
|
||
docMockMvc = MockMvcBuilders.webAppContextSetup( context ) | ||
.apply( documentationConfiguration( restDocumentation ).uris().withPort( 8081 ) ) | ||
.alwaysDo( documentationHandler ) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
fhir/src/test/java/org/dhis2/fhir/adapter/fhir/ConstrainedFields.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.dhis2.fhir.adapter.fhir; | ||
|
||
/* | ||
* Copyright (c) 2004-2018, University of Oslo | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* Neither the name of the HISP project nor the names of its contributors may | ||
* be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
import org.springframework.restdocs.constraints.ConstraintDescriptions; | ||
import org.springframework.restdocs.payload.FieldDescriptor; | ||
import org.springframework.util.StringUtils; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; | ||
import static org.springframework.restdocs.snippet.Attributes.key; | ||
|
||
/** | ||
* Contains constrained fields of a class for REST documentation. | ||
* | ||
* @author volsch | ||
*/ | ||
public class ConstrainedFields | ||
{ | ||
private final ConstraintDescriptions constraintDescriptions; | ||
|
||
public ConstrainedFields( @Nonnull Class<?> input ) | ||
{ | ||
this.constraintDescriptions = new ConstraintDescriptions( input ); | ||
} | ||
|
||
public FieldDescriptor withPath( @Nonnull String path ) | ||
{ | ||
return fieldWithPath( path ).attributes( key( "constraints" ).value( StringUtils.collectionToDelimitedString( constraintDescriptions.descriptionsForProperty( path ), ". " ) ) ); | ||
} | ||
} |
Oops, something went wrong.