github.com/rzurga/go-swagger@v0.28.1-0.20211109195225-5d1f453ffa3a/fixtures/bugs/2385/gen-fixtures.sh (about)

     1  #! /bin/bash
     2  if [[ ${1} == "--clean" ]] ; then
     3      clean=1
     4  fi
     5  continueOnError=
     6  # A small utility to build fixture servers
     7  testcases="fixture-2385.yaml test.yaml"
     8  for opts in  "" ; do
     9  for testcase in ${testcases} ; do
    10      grep -q discriminator "${testcase}"
    11      discriminated=$?
    12      if [[ ${discriminated} -eq 0 && ${opts} == "--with-expand" ]] ; then
    13          echo "Skipped ${testcase} with ${opts}: discriminator not supported with ${opts}"
    14          continue
    15      fi
    16      if [[ ${testcase} == "../1479/fixture-1479-part.yaml" && ${opts} == "--with-expand" ]] ; then
    17          echo "Skipped ${testcase} with ${opts}: known issue with enum in anonymous allOf not validated. See you next PR"
    18          continue
    19      fi
    20  
    21      spec=${testcase}
    22      testcase=$(basename "${testcase}")
    23      if [[ -z ${opts} ]]; then
    24          target=./gen-${testcase%.*}-flatten
    25      else
    26          target=./gen-${testcase%.*}-expand
    27      fi
    28      serverName="codegensrv"
    29      rm -rf "${target}"
    30      mkdir "${target}"
    31      # simulating prexisting models
    32      mkdir -p "${target}/models"
    33      # extra models
    34      mkdir -p fred
    35      cat > fred/my_type.go << EOF
    36  package fred
    37  
    38  import (
    39  	"context"
    40    "io"
    41  
    42  	"github.com/go-openapi/strfmt"
    43  )
    44  
    45  // MyAlternateType ...
    46  type MyAlternateType string
    47  
    48  // Validate MyAlternateType
    49  func (MyAlternateType) Validate(strfmt.Registry) error                         { return nil }
    50  func (MyAlternateType) ContextValidate(context.Context, strfmt.Registry) error { return nil }
    51  
    52  // MyAlternateInteger ...
    53  type MyAlternateInteger int
    54  
    55  // Validate MyAlternateInteger
    56  func (MyAlternateInteger) Validate(strfmt.Registry) error                         { return nil }
    57  func (MyAlternateInteger) ContextValidate(context.Context, strfmt.Registry) error { return nil }
    58  
    59  // MyAlternateString ...
    60  type MyAlternateString string
    61  
    62  // Validate MyAlternateString
    63  func (MyAlternateString) Validate(strfmt.Registry) error                         { return nil }
    64  func (MyAlternateString) ContextValidate(context.Context, strfmt.Registry) error { return nil }
    65  
    66  // MyAlternateOtherType ...
    67  type MyAlternateOtherType struct{}
    68  
    69  // Validate MyAlternateOtherType
    70  func (MyAlternateOtherType) Validate(strfmt.Registry) error                         { return nil }
    71  func (MyAlternateOtherType) ContextValidate(context.Context, strfmt.Registry) error { return nil }
    72  
    73  // MyAlternateStreamer ...
    74  type MyAlternateStreamer io.Reader
    75  
    76  // MyAlternateInterface ...
    77  type MyAlternateInterface interface{}
    78  EOF
    79  
    80      mkdir -p go-ext
    81      cat > go-ext/my_type.go << EOF
    82  package ext
    83  
    84  import (
    85  	"context"
    86  
    87  	"github.com/go-openapi/strfmt"
    88  )
    89  
    90  type MyExtType struct {}
    91  
    92  func (MyExtType) Validate(strfmt.Registry) error                         { return nil }
    93  func (MyExtType) ContextValidate(context.Context, strfmt.Registry) error { return nil }
    94  EOF
    95  
    96      cat > ${target}/models/my_type.go << EOF
    97  package models
    98  
    99  import (
   100    "context"
   101    "io"
   102    "github.com/go-openapi/strfmt"
   103  )
   104  
   105  // MyType ...
   106  type MyType string
   107  
   108  // Validate MyType
   109  func (MyType) Validate(strfmt.Registry) error { return nil }
   110  func (MyType) ContextValidate(context.Context, strfmt.Registry) error { return nil }
   111  
   112  // MyInteger ...
   113  type MyInteger int
   114  
   115  // Validate MyInteger
   116  func (MyInteger) Validate(strfmt.Registry) error { return nil }
   117  func (MyInteger) ContextValidate(context.Context, strfmt.Registry) error { return nil }
   118  
   119  // MyString ...
   120  type MyString string
   121  
   122  // Validate MyString
   123  func (MyString) Validate(strfmt.Registry) error { return nil }
   124  func (MyString) ContextValidate(context.Context, strfmt.Registry) error { return nil }
   125  
   126  // MyOtherType ...
   127  type MyOtherType struct{}
   128  
   129  // Validate MyOtherType
   130  func (MyOtherType) Validate(strfmt.Registry) error { return nil }
   131  func (MyOtherType) ContextValidate(context.Context, strfmt.Registry) error { return nil }
   132  
   133  // MyStreamer ...
   134  type MyStreamer io.Reader
   135  
   136  EOF
   137  
   138      echo "Model generation for ${spec} with opts=${opts}"
   139      serverName="nrcodegen"
   140      swagger generate server --skip-validation ${opts} --spec ${spec} --target ${target} --name=${serverName} 1>${testcase%.*}.log 2>&1
   141      # 1>x.log 2>&1
   142      #
   143      if [[ $? != 0 ]] ; then
   144          echo "Generation failed for ${spec}"
   145          if [[ ! -z ${continueOnError} ]] ; then
   146              failures="${failures} codegen:${spec}"
   147              continue
   148          else
   149              exit 1
   150          fi
   151      fi
   152      echo "${spec}: Generation OK"
   153      if [[ ! -d ${target}/models ]] ; then
   154          echo "No model in this spec! Continue building server"
   155      fi
   156      if [[ -d ${target}/cmd/${serverName}"-server" ]] ; then
   157          (cd ${target}/cmd/${serverName}"-server"; go build)
   158          #(cd ${target}/models; go build)
   159          if [[ $? != 0 ]] ; then
   160              echo "Build failed for ${spec}"
   161              if [[ ! -z ${continueOnError} ]] ; then
   162                  failures="${failures} build:${spec}"
   163                  continue
   164              else
   165                  exit 1
   166              fi
   167          fi
   168          echo "${spec}: Build OK"
   169          if [[ -n ${clean} ]] ; then
   170               rm -rf ${target}
   171          fi
   172      fi
   173  done
   174  done
   175  if [[ ! -z ${failures} ]] ; then
   176      echo ${failures}|tr ' ' '\n'
   177  else
   178      echo "No failures"
   179  fi
   180  exit