Skip to content
Snippets Groups Projects
Select Git revision
  • e02ec209a671e243da044e84609135ac908d4c0c
  • main default protected
  • dev protected
  • Issue/3133-subProjectsChanges
  • Issue/2489-addNotificationManagement
  • Issue/3085-useNewApiClient
  • Issue/3043-DataStorageNrwResource
  • Issue/3011-maintenanceMode
  • Issue/2446-addingResponsibleOrganization
  • Issue/2900-removeInsituteField
  • Issue/2981-dataPubInDb
  • Issue/2881-messageController
  • Issue/2921-changesToDataPublicationFeature
  • Issue/2926-regAppLogin
  • Issue/2672-fixSfbPidPointing
  • Issue/2875-devcontainer
  • Issue/2401-advisoryServiceUI2
  • Issue/2445-extractedMetadata
  • Issue/2829-useHrefProperty
  • Issue/xxxx-configurableApiHostname
  • Issue/2627-addPidRecord
  • v3.18.0
  • v3.17.0
  • v3.16.0
  • v3.15.0
  • v3.14.0
  • v3.13.0
  • v3.12.0
  • v3.11.0
  • v3.10.0
  • v3.9.0
  • v3.8.0
  • v3.7.0
  • v3.6.0
  • v3.5.0
  • v3.4.3
  • v3.4.2
  • v3.4.1
  • v3.4.0
  • v3.3.2-package.0
  • v3.3.1
41 results

generate-api-client.sh

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    generate-api-client.sh 2.34 KiB
    #!/bin/bash
    
    # --------------------------------------------------------------------------------------------------------------------------------------------------------------------
    # Generate TypeScript API Client using OpenAPI Generator:
    # --------------------------------------------------------------------------------------------------------------------------------------------------------------------
    # This script generates a TypeScript API client based on the OpenAPI specification.
    #
    # The actions performed are:
    # - Generating the API client code using podman (make sure it's available).
    # - Deleting existing API client source files.
    # - Copying the newly generated API client source to the project directory.
    # - Cleaning up temporary files.
    #
    # Defined variables:
    OUTPUT_DIR="temp"                                     # The temporary directory for generated files
    PACKAGE_NAME="Coscine.Api"                            # The package name for the API client
    API_SPEC_URL="https://coscine-hristov.web.vulcanus.otc.coscine.dev/coscine/api/swagger/v2/swagger.json" # URL to the OpenAPI spec file
    # --------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    # ANSI color codes for styling
    GREEN='\033[0;32m'
    YELLOW='\033[0;33m'
    CYAN='\033[0;36m'
    NC='\033[0m' # No Color
    
    # Run the OpenAPI generator
    echo -e "${CYAN}Running the OpenAPI generator...${NC}"
    podman run --rm \
      -v ${PWD}:/local openapitools/openapi-generator-cli generate \
      -i "$API_SPEC_URL" \
      -g typescript-axios \
      -o /local/$OUTPUT_DIR \
      --additional-properties=useSingleRequestParameter=true,apiPackage=@coscine/api,modelPackage=@coscine/model,withSeparateModelsAndApi=true,enumPropertyNaming=original \
      --skip-validate-spec
    
    echo -e "${GREEN}API client generation complete.${NC}"
    
    # Delete the current API client source
    echo -e "${YELLOW}Deleting current API client source...${NC}"
    rm -rf "src/$PACKAGE_NAME"
    
    # Copy the generated API client source to the src directory
    echo -e "${CYAN}Copying generated API client source to src directory...${NC}"
    cp -r "$OUTPUT_DIR/" "src/$PACKAGE_NAME"
    
    # Remove the temp directory
    echo -e "${YELLOW}Cleaning up...${NC}"
    rm -rf "$OUTPUT_DIR"
    
    echo -e "${GREEN}Finished.${NC}"
    
    echo -e "${YELLOW}Don't forget to add newly generated apis to apis.ts and index.ts!!${NC}"