diff --git a/samples/rest-notes-grails/build.gradle b/samples/rest-notes-grails/build.gradle index 64e2e6d8..c0bce855 100644 --- a/samples/rest-notes-grails/build.gradle +++ b/samples/rest-notes-grails/build.gradle @@ -1,36 +1,26 @@ buildscript { - ext { - grailsVersion = project.grailsVersion - } repositories { - mavenLocal() maven { url "https://repo.grails.org/grails/core" } - maven { url 'https://repo.spring.io/libs-snapshot' } } dependencies { classpath "org.grails:grails-gradle-plugin:$grailsVersion" - classpath "org.grails.plugins:hibernate:4.3.10.5" - classpath 'org.ajoberstar:gradle-git:1.1.0' + classpath "org.grails.plugins:hibernate5:6.0.7" } } plugins { - id "io.spring.dependency-management" version "0.5.4.RELEASE" id 'org.asciidoctor.convert' version '1.5.3' } version "0.1" group "com.example" -apply plugin: "spring-boot" apply plugin: "war" -apply plugin: 'eclipse' -apply plugin: 'idea' +apply plugin: "eclipse" +apply plugin: "idea" apply plugin: "org.grails.grails-web" ext { - grailsVersion = project.grailsVersion - gradleWrapperVersion = project.gradleWrapperVersion restDocsVersion = "1.2.0.BUILD-SNAPSHOT" snippetsDir = file('src/docs/generated-snippets') } @@ -43,12 +33,12 @@ repositories { dependencyManagement { dependencies { + dependency "org.springframework.restdocs:spring-restdocs-core:$restDocsVersion" dependency "org.springframework.restdocs:spring-restdocs-restassured:$restDocsVersion" dependency "org.springframework.restdocs:spring-restdocs-asciidoctor:$restDocsVersion" } imports { mavenBom "org.grails:grails-bom:$grailsVersion" - mavenBom "org.springframework:spring-framework-bom:4.3.1.RELEASE" } applyMavenExclusions false } @@ -57,11 +47,13 @@ dependencies { asciidoctor "org.springframework.restdocs:spring-restdocs-asciidoctor" compile "org.springframework.boot:spring-boot-starter-logging" - compile "org.springframework.boot:spring-boot-starter-actuator" compile "org.springframework.boot:spring-boot-autoconfigure" + compile "org.springframework.boot:spring-boot-starter-actuator" compile "org.springframework.boot:spring-boot-starter-tomcat" + compile "org.grails:grails-core" compile "org.grails:grails-plugin-url-mappings" compile "org.grails:grails-plugin-rest" + compile "org.grails:grails-plugin-codecs" compile "org.grails:grails-plugin-interceptors" compile "org.grails:grails-plugin-services" compile "org.grails:grails-plugin-datasource" @@ -69,22 +61,25 @@ dependencies { compile "org.grails:grails-plugin-async" compile "org.grails:grails-web-boot" compile "org.grails:grails-logging" - - compile "org.grails.plugins:hibernate" compile "org.grails.plugins:cache" - compile "org.hibernate:hibernate-ehcache" + compile "org.grails.plugins:hibernate5" + compile "org.hibernate:hibernate-core:5.1.2.Final" + compile "org.hibernate:hibernate-ehcache:5.1.2.Final" + compile "org.grails.plugins:views-json" + compile "org.grails.plugins:views-json-templates" + console "org.grails:grails-console" + + profile "org.grails.profiles:rest-api" runtime "com.h2database:h2" testCompile "org.grails:grails-plugin-testing" testCompile "org.grails.plugins:geb" - testCompile 'org.springframework.restdocs:spring-restdocs-restassured' + testCompile "org.grails:grails-datastore-rest-client" + testCompile "org.springframework.restdocs:spring-restdocs-restassured" - console "org.grails:grails-console" -} - -task wrapper(type: Wrapper) { - gradleVersion = gradleWrapperVersion + testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1" + testRuntime "net.sourceforge.htmlunit:htmlunit:2.18" } ext { diff --git a/samples/rest-notes-grails/gradle.properties b/samples/rest-notes-grails/gradle.properties index 1b1c50f8..d8bda96d 100644 --- a/samples/rest-notes-grails/gradle.properties +++ b/samples/rest-notes-grails/gradle.properties @@ -1,2 +1,2 @@ -grailsVersion=3.0.15 -gradleWrapperVersion=2.3 +grailsVersion=3.2.6 +gradleWrapperVersion=3.4 \ No newline at end of file diff --git a/samples/rest-notes-grails/grails-app/conf/application.yml b/samples/rest-notes-grails/grails-app/conf/application.yml index 3fe5b297..915c149a 100644 --- a/samples/rest-notes-grails/grails-app/conf/application.yml +++ b/samples/rest-notes-grails/grails-app/conf/application.yml @@ -1,6 +1,6 @@ --- grails: - profile: web-api + profile: rest-api codegen: defaultPackage: com.example info: diff --git a/samples/rest-notes-grails/grails-app/controllers/com/example/IndexController.groovy b/samples/rest-notes-grails/grails-app/controllers/com/example/IndexController.groovy deleted file mode 100644 index 01f58518..00000000 --- a/samples/rest-notes-grails/grails-app/controllers/com/example/IndexController.groovy +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example - -import grails.core.GrailsApplication -import grails.util.Environment - -class IndexController { - - GrailsApplication grailsApplication - - def index() { - render(contentType: 'application/json') { - message = "Welcome to Grails!" - environment = Environment.current.name - appversion = grailsApplication.metadata['info.app.version'] - grailsversion = grailsApplication.metadata['info.app.grailsVersion'] - appprofile = grailsApplication.config.grails?.profile - groovyversion = GroovySystem.getVersion() - jvmversion = System.getProperty('java.version') - controllers = array { - for (c in grailsApplication.controllerClasses) { - controller([name: c.fullName]) - } - } - plugins = array { - for (p in grailsApplication.mainContext.pluginManager.allPlugins) { - plugin([name: p.fullName]) - } - } - } - } - -} diff --git a/samples/rest-notes-grails/grails-app/controllers/com/example/InternalServerErrorController.groovy b/samples/rest-notes-grails/grails-app/controllers/com/example/InternalServerErrorController.groovy deleted file mode 100644 index c0e80312..00000000 --- a/samples/rest-notes-grails/grails-app/controllers/com/example/InternalServerErrorController.groovy +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example - -class InternalServerErrorController { - - def index() { - render(contentType: 'application/json') { - error = 500 - message = "Internal server error" - } - } - -} diff --git a/samples/rest-notes-grails/grails-app/controllers/com/example/NotFoundController.groovy b/samples/rest-notes-grails/grails-app/controllers/com/example/NotFoundController.groovy deleted file mode 100644 index 039968a9..00000000 --- a/samples/rest-notes-grails/grails-app/controllers/com/example/NotFoundController.groovy +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example - -class NotFoundController { - - def index() { - render(contentType: 'application/json') { - error = 404 - message = "Not Found" - } - } - -} diff --git a/samples/rest-notes-grails/grails-app/controllers/UrlMappings.groovy b/samples/rest-notes-grails/grails-app/controllers/com/example/UrlMappings.groovy similarity index 58% rename from samples/rest-notes-grails/grails-app/controllers/UrlMappings.groovy rename to samples/rest-notes-grails/grails-app/controllers/com/example/UrlMappings.groovy index 7d8cffe5..190e41e3 100644 --- a/samples/rest-notes-grails/grails-app/controllers/UrlMappings.groovy +++ b/samples/rest-notes-grails/grails-app/controllers/com/example/UrlMappings.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,20 @@ * limitations under the License. */ +package com.example + class UrlMappings { static mappings = { - "/"(controller: 'index') - "500"(controller: 'InternalServerError') - "404"(controller: 'NotFound') + delete "/$controller/$id(.$format)?"(action:"delete") + get "/$controller(.$format)?"(action:"index") + get "/$controller/$id(.$format)?"(action:"show") + post "/$controller(.$format)?"(action:"save") + put "/$controller/$id(.$format)?"(action:"update") + patch "/$controller/$id(.$format)?"(action:"patch") + + "500"(view: '/error') + "404"(view: '/notFound') } } diff --git a/samples/rest-notes-grails/grails-app/init/BootStrap.groovy b/samples/rest-notes-grails/grails-app/init/com/example/BootStrap.groovy similarity index 97% rename from samples/rest-notes-grails/grails-app/init/BootStrap.groovy rename to samples/rest-notes-grails/grails-app/init/com/example/BootStrap.groovy index 0efbc954..92ec4c14 100644 --- a/samples/rest-notes-grails/grails-app/init/BootStrap.groovy +++ b/samples/rest-notes-grails/grails-app/init/com/example/BootStrap.groovy @@ -14,7 +14,7 @@ * limitations under the License. */ -import com.example.Note +package com.example class BootStrap { diff --git a/samples/rest-notes-grails/grails-app/views/error.gson b/samples/rest-notes-grails/grails-app/views/error.gson new file mode 100644 index 00000000..314e80db --- /dev/null +++ b/samples/rest-notes-grails/grails-app/views/error.gson @@ -0,0 +1,6 @@ +response.status 500 + +json { + message "Internal server error" + error 500 +} \ No newline at end of file diff --git a/samples/rest-notes-grails/grails-app/views/notFound.gson b/samples/rest-notes-grails/grails-app/views/notFound.gson new file mode 100644 index 00000000..1a710b26 --- /dev/null +++ b/samples/rest-notes-grails/grails-app/views/notFound.gson @@ -0,0 +1,6 @@ +response.status 404 + +json { + message "Not Found" + error 404 +} \ No newline at end of file diff --git a/samples/rest-notes-grails/src/docs/asciidoc/index.adoc b/samples/rest-notes-grails/src/docs/asciidoc/index.adoc index 231af2ec..c1dd3596 100644 --- a/samples/rest-notes-grails/src/docs/asciidoc/index.adoc +++ b/samples/rest-notes-grails/src/docs/asciidoc/index.adoc @@ -62,30 +62,6 @@ use of HTTP status codes. = Resources -[[resources-index]] -== Index - -The index provides the entry point into the service. - - - -[[resources-index-access]] -=== Accessing the index - -A `GET` request is used to access the index - -==== Example request - -include::{snippets}/index-example/curl-request.adoc[] - -==== Response structure - -include::{snippets}/index-example/response-fields.adoc[] - -==== Example response - -include::{snippets}/index-example/http-response.adoc[] - [[resources-notes]] == Notes diff --git a/samples/rest-notes-grails/src/integration-test/groovy/com/example/ApiDocumentationSpec.groovy b/samples/rest-notes-grails/src/integration-test/groovy/com/example/ApiDocumentationSpec.groovy index 102426b9..2e15d73b 100644 --- a/samples/rest-notes-grails/src/integration-test/groovy/com/example/ApiDocumentationSpec.groovy +++ b/samples/rest-notes-grails/src/integration-test/groovy/com/example/ApiDocumentationSpec.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,34 +59,6 @@ class ApiDocumentationSpec extends Specification { .build() } - void 'test and document get request for /index'() { - expect: - given(this.documentationSpec) - .accept(MediaType.APPLICATION_JSON.toString()) - .filter(document('index-example', - preprocessRequest(modifyUris() - .host('api.example.com') - .removePort()), - preprocessResponse(prettyPrint()), - responseFields( - fieldWithPath('message').description('Welcome to Grails!'), - fieldWithPath('environment').description("The running environment"), - fieldWithPath('appversion').description('version of the app that is running'), - fieldWithPath('grailsversion').description('the version of grails used in this project'), - fieldWithPath('appprofile').description('the profile of grails used in this project'), - fieldWithPath('groovyversion').description('the version of groovy used in this project'), - fieldWithPath('jvmversion').description('the version of the jvm used in this project'), - subsectionWithPath('controllers').type(JsonFieldType.ARRAY).description('the list of available controllers'), - subsectionWithPath('plugins').type(JsonFieldType.ARRAY).description('the plugins active for this project'), - ))) - .when() - .port(this.serverPort) - .get('/') - .then() - .assertThat() - .statusCode(is(200)) - } - void 'test and document notes list request'() { expect: given(this.documentationSpec) @@ -97,7 +69,6 @@ class ApiDocumentationSpec extends Specification { .removePort()), preprocessResponse(prettyPrint()), responseFields( - fieldWithPath('[].class').description('the class of the resource'), fieldWithPath('[].id').description('the id of the note'), fieldWithPath('[].title').description('the title of the note'), fieldWithPath('[].body').description('the body of the note'), @@ -127,7 +98,6 @@ class ApiDocumentationSpec extends Specification { subsectionWithPath('tags').type(JsonFieldType.ARRAY).description('a list of tags associated to the note') ), responseFields( - fieldWithPath('class').description('the class of the resource'), fieldWithPath('id').description('the id of the note'), fieldWithPath('title').description('the title of the note'), fieldWithPath('body').description('the body of the note'), @@ -152,7 +122,6 @@ class ApiDocumentationSpec extends Specification { .removePort()), preprocessResponse(prettyPrint()), responseFields( - fieldWithPath('class').description('the class of the resource'), fieldWithPath('id').description('the id of the note'), fieldWithPath('title').description('the title of the note'), fieldWithPath('body').description('the body of the note'),