summaryrefslogtreecommitdiffstats
path: root/python_openapi_client/codegen_python_client.sh
blob: aab3bddbd35b47c3694e551df58554b6f39fb8ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash

# This script re-generates the fatcat API client (fatcat-openapi-client) from the
# swagger/openapi2 spec file, using automated tools ("codegen")

set -exu
set -o pipefail

OUTPUT=`pwd`/codegen-out
mkdir -p $OUTPUT
# Strip tags, so entire API is under a single class
# Also strip long part of description so it doesn't clutter source headers
cat ../fatcat-openapi2.yml | grep -v "TAGLINE$" | perl -0777 -pe "s/<\!-- STARTLONGDESCRIPTION -->.*<\!-- ENDLONGDESCRIPTION -->//s" > $OUTPUT/api.yml

docker run \
    -v $OUTPUT:/tmp/swagger/ \
    swaggerapi/swagger-codegen-cli:v2.3.1 \
    generate \
    --lang python \
    --input-spec /tmp/swagger/api.yml \
    --output /tmp/swagger/ \
    -DpackageName=fatcat_openapi_client

sudo chown -R `whoami`:`whoami` $OUTPUT
mkdir -p fatcat_openapi_client
cp -r $OUTPUT/fatcat_openapi_client/* fatcat_openapi_client
cp $OUTPUT/README.md README.md

# fix an annoying/buggy __del__() in codegen
patch -p0 << END_PATCH
--- fatcat_openapi_client/api_client.py
+++ fatcat_openapi_client/api_client.py
@@ -76,8 +76,11 @@ class ApiClient(object):
         self.user_agent = 'Swagger-Codegen/1.0.0/python'
 
     def __del__(self):
-        self.pool.close()
-        self.pool.join()
+        try:
+            self.pool.close()
+            self.pool.join()
+        except:
+            pass
 
     @property
     def user_agent(self):
END_PATCH

# I don't know what they were thinking with this TypeWithDefault stuff, but it
# caused really gnarly config cross-contamination issues when running mulitple
# clients in parallel.
# See also: https://github.com/swagger-api/swagger-codegen/issues/9117
patch -p0 << END_PATCH
--- fatcat_openapi_client/configuration.py
+++ fatcat_openapi_client/configuration.py
@@ -37,7 +37,7 @@ class TypeWithDefault(type):
         cls._default = copy.copy(default)
 
 
-class Configuration(six.with_metaclass(TypeWithDefault, object)):
+class Configuration(object):
     """NOTE: This class is auto generated by the swagger code generator program.
 
     Ref: https://github.com/swagger-api/swagger-codegen
END_PATCH

# fix circular import (release/file/fileset/webcapture)
patch -p0 << END_PATCH
--- fatcat_openapi_client/models/file_entity.py
+++ fatcat_openapi_client/models/file_entity.py
@@ -17,7 +17,6 @@ import re  # noqa: F401
 import six
 
 from fatcat_openapi_client.models.file_url import FileUrl  # noqa: F401,E501
-from fatcat_openapi_client.models.release_entity import ReleaseEntity  # noqa: F401,E501
 
 
 class FileEntity(object):
--- fatcat_openapi_client/models/fileset_entity.py
+++ fatcat_openapi_client/models/fileset_entity.py
@@ -18,7 +18,6 @@ import six
 
 from fatcat_openapi_client.models.fileset_file import FilesetFile  # noqa: F401,E501
 from fatcat_openapi_client.models.fileset_url import FilesetUrl  # noqa: F401,E501
-from fatcat_openapi_client.models.release_entity import ReleaseEntity  # noqa: F401,E501
 
 
 class FilesetEntity(object):
--- fatcat_openapi_client/models/webcapture_entity.py
+++ fatcat_openapi_client/models/webcapture_entity.py
@@ -16,7 +16,6 @@ import re  # noqa: F401
 
 import six
 
-from fatcat_openapi_client.models.release_entity import ReleaseEntity  # noqa: F401,E501
 from fatcat_openapi_client.models.webcapture_cdx_line import WebcaptureCdxLine  # noqa: F401,E501
 from fatcat_openapi_client.models.webcapture_url import WebcaptureUrl  # noqa: F401,E501
END_PATCH

# these tests are basically no-ops
mkdir -p tests/codegen
cp -r $OUTPUT/test/* tests/codegen

# ooo, this makes me nervous
rm -rf $OUTPUT