Skip to content

Commit

Permalink
genspeccia
Browse files Browse the repository at this point in the history
  • Loading branch information
oplekal committed Dec 11, 2024
1 parent b135faf commit 459df7a
Show file tree
Hide file tree
Showing 25 changed files with 144 additions and 106 deletions.
12 changes: 9 additions & 3 deletions eperusteet/eperusteet-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<!-- <springfox.version>2.7.0</springfox.version>-->
<springdoc.version>2.7.0</springdoc.version>
<surefire.version>3.2.2</surefire.version>
<swagger-maven-plugin-version>3.1.7</swagger-maven-plugin-version>
<swagger-maven-plugin-version>3.1.8</swagger-maven-plugin-version>
<jacoco.version>0.8.12</jacoco.version>
</properties>
<dependencies>
Expand Down Expand Up @@ -94,7 +94,13 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<!-- <dependency>-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-common</artifactId>
<version>1.8.0</version>
</dependency>

<!-- <dependency>-->
<!-- <groupId>io.springfox</groupId>-->
<!-- <artifactId>springfox-swagger2</artifactId>-->
<!-- <version>${springfox.version}</version>-->
Expand Down Expand Up @@ -984,7 +990,7 @@
</executions>
<configuration>
<apiDocsUrl>http://localhost:8080/eperusteet-service/api-docs</apiDocsUrl>
<outputFileName>eperusteet.json</outputFileName>
<outputFileName>eperusteet.spec.json</outputFileName>
<outputDir>${project.build.directory}/openapi</outputDir>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
package fi.vm.sade.eperusteet.config;

import com.fasterxml.jackson.databind.type.SimpleType;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.media.Schema;
import org.springdoc.core.customizers.OpenApiCustomiser;
import org.springdoc.core.customizers.PropertyCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.ResolvableType;

import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

@Configuration
//@EnableSwagger2
Expand Down Expand Up @@ -45,9 +56,23 @@ public class SwaggerConfig {
public OpenAPI springShopOpenAPI() {
return new OpenAPI()
.info(new Info()
.title("ePerusteet rajapinta")
.description("Spring MVC API based on the swagger 3.0 specification")
.version("v3.0.0")
.license(new License().name("EUPL 1.1").url("https://interoperable-europe.ec.europa.eu/licence/european-union-public-licence-version-11-or-later-eupl")));
.title("ePerusteet rajapinta")
.description("Spring MVC API based on the swagger 3.0 specification")
.version("v3.0.0")
.license(new License().name("EUPL 1.1").url("https://interoperable-europe.ec.europa.eu/licence/european-union-public-licence-version-11-or-later-eupl")));
}

@Bean
public PropertyCustomizer enumPropertyCustomizer() {
return (schema, type) -> {
Type javaType = type.getType();
if (javaType instanceof SimpleType && ((SimpleType) javaType).isEnumType()) {
Class<?> enumClass = ((SimpleType)javaType).getRawClass();
schema.setEnum(Arrays.stream(enumClass.getEnumConstants())
.map(enumConstant -> ((Enum<?>) enumConstant).name())
.collect(Collectors.toList()));
}
return schema;
};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fi.vm.sade.eperusteet.domain;

import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.Arrays;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fi.vm.sade.eperusteet.domain;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import fi.vm.sade.eperusteet.dto.util.JsonSerializableEnum;

public enum Suoritustapakoodi {

Expand Down Expand Up @@ -38,4 +40,9 @@ public static Suoritustapakoodi of(String koodi) {
}
throw new IllegalArgumentException(koodi + " ei ole kelvollinen suoritustapakoodi");
}

@JsonValue
public String value() {
return name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
import fi.vm.sade.eperusteet.domain.ReferenceableEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.UUID;
Expand Down Expand Up @@ -32,7 +33,7 @@ public Reference(String id) {
}

@JsonValue
public String getId() {
public Object getId() {
return id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import fi.vm.sade.eperusteet.dto.util.LokalisoituTekstiDto;
import java.util.Date;

import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -28,5 +30,6 @@ public class PerusteKevytDto {
private Reference perusteprojekti;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
// @Schema(type = "array")
private Set<SuoritustapaDto> suoritustavat;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import fi.vm.sade.eperusteet.dto.Reference;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -15,6 +16,7 @@
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(Include.NON_NULL)
@Schema(name = "PerusteenOsaViiteDto")
public class PerusteenOsaViiteDto<R extends PerusteenOsaDto> {

private Long id;
Expand Down Expand Up @@ -44,6 +46,7 @@ public Matala(PerusteenOsaDto.Laaja perusteenOsa) {
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "PuuPerusteenOsaDto")
public static class Puu<R extends PerusteenOsaDto, L extends Puu<R, L>> extends PerusteenOsaViiteDto<R> {
private List<L> lapset;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RakenneOsaDto extends AbstractRakenneOsaDto {
@Override
public String validationIdentifier() {
return tutkinnonOsaViite != null
? tutkinnonOsaViite.getId()
? tutkinnonOsaViite.toString()
: "";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fi.vm.sade.eperusteet.dto.util;

import com.fasterxml.jackson.annotation.JsonValue;

public interface JsonSerializableEnum {
@JsonValue
default String value() {
return ((Enum<?>) this).name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonValue;
import fi.vm.sade.eperusteet.domain.Kieli;
import fi.vm.sade.eperusteet.domain.TekstiPalanen;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
Expand Down Expand Up @@ -95,8 +96,8 @@ else if ("_tunniste".equals(entry.getKey())) {
}

@JsonValue
public Map<String, Object> asMap() {
HashMap<String, Object> map = new HashMap<>();
public Map<String, String> asMap() {
HashMap<String, String> map = new HashMap<>();
if (id != null) {
map.put("_id", id.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import java.util.Map;
import java.util.UUID;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Data
@EqualsAndHashCode(callSuper = true)
public class NavigableLokalisoituTekstiDto extends LokalisoituTekstiDto {

@Setter
@Getter
private NavigationNodeDto navigationNode;

public NavigableLokalisoituTekstiDto(Long id, Map<Kieli, String> values, NavigationNodeDto navigationNode) {
Expand Down Expand Up @@ -45,26 +45,4 @@ public NavigableLokalisoituTekstiDto(PerusteenOsa perusteenOsa) {
perusteenOsa.getViitteet().stream().findFirst().get().getId()));
}

public NavigableLokalisoituTekstiDto(Long id, UUID tunniste, Map<Kieli, String> values) {
super(id, tunniste, values);
}

public NavigableLokalisoituTekstiDto(Map<String, String> values) {
super(values);
}

public NavigableLokalisoituTekstiDto(Long id, Map<Kieli, String> values) {
super(id, values);
}

@Override
@JsonValue
public Map<String, Object> asMap() {
Map<String, Object> map = super.asMap();
if(navigationNode != null) {
map.put("navigationNode", navigationNode);
}

return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import fi.vm.sade.eperusteet.dto.util.LokalisoituTekstiDto;
import fi.vm.sade.eperusteet.service.KoodistoClient;
import fi.vm.sade.eperusteet.service.KoodistoPagedService;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -48,8 +49,7 @@ public ResponseEntity<List<KoodistoKoodiDto>> kaikki(
public ResponseEntity<Page<KoodistoKoodiDto>> kaikkiSivutettuna(
@PathVariable("koodisto") final String koodisto,
@RequestParam(value = "haku", required = false) final String haku,
KoodistoPageDto koodistoPageDto) {

@Schema(hidden = true) KoodistoPageDto koodistoPageDto) {
return new ResponseEntity<>(koodistoPagedService.getAllPaged(koodisto, haku, koodistoPageDto), HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public ResponseEntity<OpasDto> addOpas(
@Parameter(name = "sivu", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY),
@Parameter(name = "sivukoko", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY),
@Parameter(name = "nimi", schema = @Schema(implementation = String.class), in = ParameterIn.QUERY),
@Parameter(name = "kieli", schema = @Schema(implementation = String.class, defaultValue = "fi"), in = ParameterIn.QUERY, description = "oppaan nimen kieli"),
@Parameter(name = "kieli", schema = @Schema(implementation = String.class, defaultValue = "fi"), array = @ArraySchema(schema = @Schema(type = "string")), in = ParameterIn.QUERY, description = "oppaan nimen kieli"),
@Parameter(name = "muokattu", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY, description = "muokattu jälkeen (aikaleima; millisenkunteja alkaen 1970-01-01 00:00:00 UTC)"),
@Parameter(name = "koulutustyyppi", schema = @Schema(implementation = String.class), in = ParameterIn.QUERY, array=@ArraySchema(schema = @Schema()), description = "koulutustyyppi (koodistokoodi)"),
@Parameter(name = "koulutustyyppi", in = ParameterIn.QUERY, array = @ArraySchema(schema = @Schema(type = "string")), description = "koulutustyyppi (koodistokoodi)"),
@Parameter(name = "tuleva", schema = @Schema(implementation = Boolean.class, defaultValue = "true"), in = ParameterIn.QUERY, description = "hae myös tulevat perusteet"),
@Parameter(name = "voimassaolo", schema = @Schema(implementation = Boolean.class, defaultValue = "true"), in = ParameterIn.QUERY, description = "hae myös voimassaolevat perusteet"),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class OsaamismerkkiController {
@Parameter(name = "sivu", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY),
@Parameter(name = "sivukoko", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY),
@Parameter(name = "nimi", schema = @Schema(implementation = String.class), in = ParameterIn.QUERY),
@Parameter(name = "tila", schema = @Schema(implementation = String.class), in = ParameterIn.QUERY, array=@ArraySchema(schema = @Schema())),
@Parameter(name = "koodit", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY, array=@ArraySchema(schema = @Schema())),
@Parameter(name = "tila", array = @ArraySchema(schema = @Schema(type = "string")), in = ParameterIn.QUERY),
@Parameter(name = "koodit", array = @ArraySchema(schema = @Schema(type = "number")), in = ParameterIn.QUERY),
@Parameter(name = "kategoria", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY),
@Parameter(name = "voimassa", schema = @Schema(implementation = Boolean.class), in = ParameterIn.QUERY),
@Parameter(name = "tuleva", schema = @Schema(implementation = Boolean.class), in = ParameterIn.QUERY),
Expand All @@ -62,7 +62,7 @@ public Page<OsaamismerkkiDto> findOsaamismerkitBy(@Parameter(hidden = true) Osaa
@Parameters({
@Parameter(name = "nimi", schema = @Schema(implementation = String.class), in = ParameterIn.QUERY),
@Parameter(name = "kategoria", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY),
@Parameter(name = "koodit", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY, array=@ArraySchema(schema = @Schema())),
@Parameter(name = "koodit", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY, array = @ArraySchema(schema = @Schema(type = "number"))),
@Parameter(name = "poistunut", schema = @Schema(implementation = Boolean.class), in = ParameterIn.QUERY),
@Parameter(name = "kieli", schema = @Schema(implementation = String.class), in = ParameterIn.QUERY)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ public PerusteprojektiDto updatePerusteprojekti(
@ResponseBody
public TilaUpdateStatus updatePerusteprojektiTila(
@PathVariable("id") final long id,
@PathVariable("tila") final String tila,
@RequestBody TiedoteDto tiedoteDto
@PathVariable("tila") final String tila
) {
return service.updateTila(id, ProjektiTila.of(tila), tiedoteDto);
return service.updateTila(id, ProjektiTila.of(tila), null);
}

@RequestMapping(value = "/{id}/projekti/tila/{tila}", method = POST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public void initBinder(final WebDataBinder webdataBinder) {
@Parameters({
@Parameter(name = "sivu", schema = @Schema(implementation = Integer.class), in = ParameterIn.QUERY),
@Parameter(name = "sivukoko", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY),
@Parameter(name = "kieli", schema = @Schema(implementation = String.class), in = ParameterIn.QUERY, array=@ArraySchema(schema = @Schema()), description = "tiedotteen kieli"),
@Parameter(name = "kieli", in = ParameterIn.QUERY, array = @ArraySchema(schema = @Schema(type = "string")), description = "tiedotteen kieli"),
@Parameter(name = "nimi", schema = @Schema(implementation = String.class), in = ParameterIn.QUERY, description = "hae nimellä"),
@Parameter(name = "perusteId", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY, description = "hae perusteeseen liitetyt tiedotteet"),
@Parameter(name = "perusteeton", schema = @Schema(implementation = Boolean.class, defaultValue = "true"), in = ParameterIn.QUERY, description = "hae perusteettomat tiedotteet"),
@Parameter(name = "julkinen", schema = @Schema(implementation = Boolean.class, defaultValue = "true"), in = ParameterIn.QUERY, description = "hae julkiset tiedotteet"),
@Parameter(name = "yleinen", schema = @Schema(implementation = Boolean.class, defaultValue = "true"), in = ParameterIn.QUERY, description = "hae yleiset tiedotteet"),
@Parameter(name = "tiedoteJulkaisuPaikka", schema = @Schema(implementation = String.class), in = ParameterIn.QUERY, array=@ArraySchema(schema = @Schema()), description = "tiedotteen julkaisupaikat"),
@Parameter(name = "perusteIds", schema = @Schema(implementation = Long.class), in = ParameterIn.QUERY, array=@ArraySchema(schema = @Schema()), description = "tiedotteen perusteiden"),
@Parameter(name = "koulutusTyyppi", schema = @Schema(implementation = String.class), in = ParameterIn.QUERY, array=@ArraySchema(schema = @Schema()), description = "tiedotteen koulutustyypit"),
@Parameter(name = "tiedoteJulkaisuPaikka", in = ParameterIn.QUERY, array = @ArraySchema(schema = @Schema(type = "string")), description = "tiedotteen julkaisupaikat"),
@Parameter(name = "perusteIds", in = ParameterIn.QUERY, array = @ArraySchema(schema = @Schema(type = "integer")), description = "tiedotteen perusteiden"),
@Parameter(name = "koulutusTyyppi", in = ParameterIn.QUERY, array = @ArraySchema(schema = @Schema(type = "string")), description = "tiedotteen koulutustyypit"),
@Parameter(name = "jarjestys", schema = @Schema(implementation = String.class), in = ParameterIn.QUERY, description = "tiedotteen jarjestys"),
@Parameter(name = "jarjestysNouseva", schema = @Schema(implementation = Boolean.class), in = ParameterIn.QUERY, description = "tiedotteen jarjestyksen suunta"),
@Parameter(name = "koulutustyypiton", schema = @Schema(implementation = Boolean.class), in = ParameterIn.QUERY, description = "koulutustyypiton tiedote"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void getKuva(
//HttpServletRequest request,
HttpServletResponse response
) throws IOException {
getLiite(perusteId, fileName, etag, "image", /*request,*/ response);
getLiite(perusteId, fileName, etag, response);
}

@RequestMapping(value = "/liitteet/{fileName}", method = RequestMethod.GET)
Expand All @@ -148,8 +148,6 @@ public void getLiite(
@PathVariable("perusteId") Long perusteId,
@PathVariable("fileName") String fileName,
@RequestHeader(value = "If-None-Match", required = false) String etag,
String topLevelMediaType,
//HttpServletRequest request,
HttpServletResponse response
) throws IOException {
UUID id = UUID.fromString(FilenameUtils.removeExtension(fileName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import fi.vm.sade.eperusteet.service.yl.OppiaineService;
import java.util.List;
import java.util.Set;

import io.swagger.v3.oas.annotations.Hidden;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -56,7 +58,7 @@

@RestController
@RequestMapping("/api/perusteet/{perusteId}/lukiokoulutus")
@InternalApi
@Hidden
public class LukiokoulutuksenPerusteenSisaltoController {
private static final Logger logger = LoggerFactory.getLogger(LukiokoulutuksenPerusteenSisaltoController.class);

Expand Down Expand Up @@ -150,7 +152,7 @@ public ResponseEntity<LukiokurssiTarkasteleDto> getKurssiByRevision(
}

@RequestMapping(value = "/kurssit/{id}/versiot/{version}/palauta", method = POST)
public LukiokurssiTarkasteleDto revertKurssi(
public LukiokurssiTarkasteleDto revertLukioKurssi(
@PathVariable("perusteId") final Long perusteId,
@PathVariable("id") Long id,
@PathVariable("version") Integer version) {
Expand Down
Loading

0 comments on commit 459df7a

Please sign in to comment.