Skip to content

Commit

Permalink
[backend/frontend] Improv swagger documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
RomuDeuxfois authored Dec 6, 2024
1 parent 1d8e16f commit fbce0f9
Show file tree
Hide file tree
Showing 55 changed files with 364 additions and 243 deletions.
5 changes: 0 additions & 5 deletions openbas-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpg-jdk18on</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.openbas.helper.MonoIdDeserializer;
import io.openbas.utils.AtomicTestingUtils;
import io.openbas.utils.AtomicTestingUtils.ExpectationResultsByType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -20,6 +21,7 @@ public class InjectExpectationResultsByAttackPattern {

@JsonSerialize(using = MonoIdDeserializer.class)
@JsonProperty("inject_attack_pattern")
@Schema(type = "string")
private AttackPattern attackPattern;

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.openbas.database.model.Exercise;
import io.openbas.helper.MonoIdDeserializer;
import io.openbas.helper.MultiModelDeserializer;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down Expand Up @@ -69,6 +70,7 @@ public class Report implements Base {
inverseJoinColumns = @JoinColumn(name = "exercise_id"))
@JsonProperty("report_exercise")
@JsonSerialize(using = MonoIdDeserializer.class)
@Schema(type = "string")
private Exercise exercise;

@OneToMany(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.openbas.database.model.Base;
import io.openbas.helper.MonoIdDeserializer;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import java.util.Objects;
Expand All @@ -30,6 +31,7 @@ public class ReportInformation implements Base {
@JoinColumn(name = "report_id")
@JsonSerialize(using = MonoIdDeserializer.class)
@NotNull
@Schema(type = "string")
private Report report;

@Enumerated(EnumType.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.openbas.database.model.Inject;
import io.openbas.helper.MonoIdDeserializer;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
Expand All @@ -21,6 +22,7 @@ public class ReportInjectComment {
@JsonIgnore // Ignore Inject object in JSON
@JsonSerialize(using = MonoIdDeserializer.class)
@NotNull
@Schema(type = "string")
private Inject inject;

@ManyToOne(fetch = FetchType.LAZY)
Expand All @@ -29,6 +31,7 @@ public class ReportInjectComment {
@JsonIgnore // Ignore Inject object in JSON
@JsonSerialize(using = MonoIdDeserializer.class)
@NotNull
@Schema(type = "string")
private Report report;

@Column(name = "comment")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.openbas.database.model.Tag;
import io.openbas.database.raw.RawScenario;
import io.openbas.helper.MultiIdSetDeserializer;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -25,6 +27,7 @@ public class ScenarioSimple {
@JsonProperty("scenario_subtitle")
private String subtitle;

@ArraySchema(schema = @Schema(type = "string"))
@JsonSerialize(using = MultiIdSetDeserializer.class)
@JsonProperty("scenario_tags")
private Set<Tag> tags = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static io.openbas.utils.pagination.SortUtilsCriteriaBuilder.toSortCriteriaBuilder;
import static java.time.Instant.now;
import static java.util.Optional.ofNullable;
import static org.springframework.util.StringUtils.hasText;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -105,7 +106,7 @@ public class ScenarioService {

@Transactional
public Scenario createScenario(@NotNull final Scenario scenario) {
if (!org.springframework.util.StringUtils.hasText(scenario.getFrom())) {
if (!hasText(scenario.getFrom())) {
if (this.imapEnabled) {
scenario.setFrom(this.imapUsername);
scenario.setReplyTos(List.of(this.imapUsername));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { UserHelper } from '../../../../actions/helper';
import SearchFilter from '../../../../components/SearchFilter';
import type { Theme } from '../../../../components/Theme';
import { useHelper } from '../../../../store';
import type { Asset } from '../../../../utils/api-types';
import type { Endpoint } from '../../../../utils/api-types';
import { useAppDispatch } from '../../../../utils/hooks';
import useDataLoader from '../../../../utils/hooks/useDataLoader';
import useSearchAnFilter from '../../../../utils/SortingFiltering';
Expand Down Expand Up @@ -55,7 +55,7 @@ interface Props {
assetGroupId: string;
handleClose: () => void;
onUpdate?: (result: AssetGroupStore) => void;
onRemoveEndpointFromAssetGroup?: (assetId: Asset['asset_id']) => void;
onRemoveEndpointFromAssetGroup?: (assetId: Endpoint['asset_id']) => void;
}

const AssetGroupManagement: FunctionComponent<Props> = ({
Expand Down
4 changes: 2 additions & 2 deletions openbas-front/src/admin/components/payloads/Payloads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ItemTags from '../../../components/ItemTags';
import PayloadIcon from '../../../components/PayloadIcon';
import PlatformIcon from '../../../components/PlatformIcon';
import { useHelper } from '../../../store';
import { PayloadStatus } from '../../../utils/api-types';
import { Payload as PayloadType } from '../../../utils/api-types';
import { useAppDispatch } from '../../../utils/hooks';
import useDataLoader from '../../../utils/hooks/useDataLoader';
import CreatePayload from './CreatePayload';
Expand Down Expand Up @@ -111,7 +111,7 @@ const chipSx = {
width: 120,
};

const fromPayloadStatusToChipColor = (payloadStatus: PayloadStatus) => {
const fromPayloadStatusToChipColor = (payloadStatus: PayloadType['payload_status']) => {
switch (payloadStatus) {
case 'VERIFIED':
return 'success';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const ScenarioForm: FunctionComponent<Props> = ({
scenario_tags: z.string().array().optional(),
scenario_external_reference: z.string().optional(),
scenario_external_url: z.string().optional(),
scenario_mail_from: z.string().email(t('Should be a valid email address')),
scenario_mail_from: z.string().email(t('Should be a valid email address')).optional(),
scenario_mails_reply_to: z.array(z.string().email(t('Should be a valid email address'))).optional(),
scenario_message_header: z.string().optional(),
scenario_message_footer: z.string().optional(),
Expand Down
Loading

0 comments on commit fbce0f9

Please sign in to comment.