Open3

Lombokを使う

horie-thorie-t

pom.xmlに以下のようにLombokの定義を追加

backend/pom.xml
<!-- 前略 -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
<!-- 中略 -->
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<excludes>
						<exclude>
							<groupId>org.projectlombok</groupId>
							<artifactId>lombok</artifactId>
						</exclude>
					</excludes>
				</configuration>
			</plugin>
<!-- 後略 -->
horie-thorie-t

データのクラスは以下のように書け、Getter, Setterのメソッドは自動的に実装されている。

backend/src/main/java/com/tehorie/tinypmt/presentation/model/TicketDTO.java
@Data
@AllArgsConstructor
public class TicketDTO {
    private String id;
    private String title;
}

これは以下と同じ。

public class TicketDTO {
    private String id;
    private String title;

    public TicketDTO(String id, String title) {
        this.id = id;
        this.title = title;
    }

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}
horie-thorie-t

Spring WebFluxでWebAPIを作成するのAPIは以下。

$ curl -v http://localhost:8080/v3/api-docs.yaml
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /v3/api-docs.yaml HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: application/vnd.oai.openapi;charset=UTF-8
< Content-Length: 694
< 
openapi: 3.0.1
info:
  title: TinyPMT API仕様
  description: TiyPMTのAPI仕様書です。
  version: v0.1
servers:
- url: http://127.0.0.1:8080
  description: Generated server url
tags:
- name: Ticket
  description: The ticket API
paths:
  /tickets:
    get:
      tags:
      - Ticket
      operationId: ListTicket
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/TicketDTO'
components:
  schemas:
    TicketDTO:
      type: object
      properties:
        id:
          type: string
        title:
          type: string
* Connection #0 to host localhost left intact